Wednesday 8 November 2017

Loops Questions in C


1. 
The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.
A. break
B. exit(0)
C. abort()
D. All of the mentioned


Answer: A
-------------------------------------------------------------------------------------

2.
The correct syntax for running two variable for loop simultaneously is.A. for (i = 0; i < n; i++)   
   for (j = 0; j < n; j += 5) 
B. for (i = 0, j = 0;i < n, j < n; i++, j += 5) 
C. for (i = 0; i < n;i++){}    
 for (j = 0; j < n;j += 5){} 
D. None of the mentioned [expand title="View Answer"] 

Answer: B
----------------------------------------------------------------------------------------

3.
 Which for loop has range of similar indexes of 'i' used in for (i = 0;i < n; i++)?
A. for (i = n; i>0; i–)
B. for (i = n; i >= 0; i–)
C. for (i = n-1; i>0; i–)
D.  for (i = n-1; i>-1; i–)


Answer: D
----------------------------------------------------------------------------------------
4. 
Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3) ?
A. Variable
B. Function
C. typedef
D. macros


Answer: D
-----------------------------------------------------------------------------------------------
5. 
What is the output of this C code?
    #include
    int main()
   {
       short i;
       for (i = 1; i >= 0; i++)
           printf("%d\n", i);
   }

A. The control won’t fall into the for loop
B. Numbers will be displayed until the signed limit of short and throw a runtime error
C. Numbers will be displayed until the signed limit of short and program will successfully terminate.
D. This program will get into an infinite loop and keep printing numbers with no errors

Answer: C
------------------------------------------------------------------------------------------------
6. 
What is the output of this C code?
#include
    void main()
    {
        int k = 0;
        for (k)
            printf("Hello");
     }


A. Compile time error
B. hello
C. Nothing
D. Varies

Answer: A
------------------------------------------------------------------------------------------------

7. 
What is the output of this C code?
#include
    void main()
    {
        int k = 0;
        for (k < 3; k++)
        printf("Hello");
    }

A. Compile time error
B. Hello is printed thrice
C. Nothing
D. Varies

Answer: A
------------------------------------------------------------------------------------------
8. 
What is the output of this C code?
#include
    void main()
    {
        double k = 0;
        for (k = 0.0; k < 3.0; k++)
            printf("Hello");
    }

A. Run time error
B. Hello is printed thrice
C. Hello is printed twice
D. Hello is printed infinitely

Answer: B
--------------------------------------------------------------------------------------------------------------


100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...