C Looping MCQ


Q1. The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
  1. break
  2. exit(0)
  3. terminate
  4. abort()

Answer:- (A).
Explanations :None.
Q2. What will be the correct syntax for running two variable for loop simultaneously?
  1. for (i = 0; i < n; i++)
    for (j = 0; j < n; j += 5)
  2. for (i = 0, j = 0; i < n, j < n; i++, j += 5)
  3. for (i = 0; i < n;i++){}
    for (j = 0; j < n;j += 5){}
  4. none of the mentioned

Answer:- (B).
Explanations :None.
Q3. Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
  1. for (i = n; i>0; i–)
  2. for (i = n; i >= 0; i–)
  3. for (i = n-1; i>0; i–)
  4. (i = n-1; i>-1; i–)

Answer:- (D).
Explanations :None.
Q4. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)??
  1. variable
  2. function
  3. typedef
  4. macros

Answer:- (D).
Explanations :None.
Q5. What will be the output of the following C code?
 #include 
    int main()
    {
        short i;
        for (i = 1; i >= 0; i++)
            printf("%d\n", i);
 
    }
  1. The control won’t fall into the for loop
  2. Numbers will be displayed until the signed limit of short and throw a runtime error.
  3. Numbers will be displayed until the signed limit of short and program will successfully terminate
  4. This program will get into an infinite loop and keep printing numbers with no errors

Answer:- (C).
Explanations :None
Q6.What will be the output of the following C code?
#include 
    void main()
    {
        int k = 0;
        for (k)
            printf("Hello");
    }
  1. Compile time error
  2. hello
  3. Nothing
  4. Varies

Answer:- (A).
Explanations :None
Q7. What will be the output of the following C code?
#include 
    void main()
    {
        int k = 0;
        for (k < 3; k++)
        printf("Hello");
    }
  1. Compile time error
  2. Hello is printed thrice
  3. Nothing
  4. Varies

Answer:- (A).
Explanations :None
Q8. What will be the output of the following C code?
#include 
    void main()
    {
        double k = 0;
        for (k = 0.0; k < 3.0; k++)
            printf("Hello");
    }
  1. Run time error
  2. Hello is printed thrice
  3. Hello is printed twice
  4. Hello is printed infinitely

Answer:- (B).
Explanations :None
Q9. What will be the output of the following C code?
#include 
    void main()
    {
        double k = 0;
        for (k = 0.0; k < 3.0; k++);
            printf("%lf", k);
    }
  1. 2.000000
  2. 4.000000
  3. 3.000000
  4. Run time error

Answer:- (C).
Explanations :None
Q10. What will be the output of the following C code?
 #include 
    void main()
    {
        int k;
        for (k = -3; k < -5; k++)
            printf("Hello");
    }
  1. Hello
  2. Infinite hello
  3. Run time error
  4. Nothing

Answer:- (D).
Explanations :None