Exercise: Questions on C Quiz 4


Questions on C Quiz 4 : Question 1 :
With respect to following “for” loops in C, pick the best statement Assume that there is a prior declaration of 'i' in all cases
for (i < 10; i = 0 ; i++) // (i)
for (i < 10; i++ ; i = 0) // (ii)
for (i = 0; i < 10 ; i++) // (iii)
for (i = 0; i++ ; i < 10) // (iv)
for (i++; i = 0 ; i < 10) // (v)
for (i++; i < 0 ; i = 10) // (vi)

All the above “for” loops would compile successfully.
All the above “for” loops would compile successfully. Except (iii), the behaviour of all the other “for” loops depend on compiler implementation.
Only (iii) would compile successfully.
Only (iii) and (iv) would compile successfully.
Only (iii) and (iv) would compile successfully but behaviour of (iv) would depend on compiler implementation.
Show Answer
Questions on C Quiz 4 : Question 2 :
With respect to following “for” loops in C, pick the best statement. Assume that there is a prior declaration of 'i' in all cases
for (i = 0; i < 10 ; i++) // (i)
for ( ; i < 10 ; i++) // (ii)
for (i = 0;  ; i++) // (iii)
for (i = 0; i < 10 ; ) // (iv)
for ( ; ; ) // (v)

Only (i) and (v) would compile successfully. Also (v) can be used as infinite loop.
Only (i) would compile successfully.
All would compile successfully but behavior of (ii), (iii) and (iv) would depend on compiler.
All would compile successfully.
Show Answer
Questions on C Quiz 4 : Question 3 :
What's going to happen when we compile and run the following C program?
 #include "stdio.h"
 
 int main()
 {
   int i = 1, j;
   for ( ; ; )
   { 
     if (i)
         j = --i;
     if (j < 10)
        printf("PROcoders", j++);
     else
        break;
   }
   return 0;
 }
 

Compile Error.
No compile error but it will run into infinite loop printing PROcoders.
No compile error and it'll print PROcoders 10 times.
No compile error but it'll print PROcoders 9 times.
Show Answer
Questions on C Quiz 4 : Question 4 :
What’s going to happen when we compile and run the following C program?
 #include "stdio.h"
 int main()
 {
  int j = 0;
  for ( ; j < 10 ; )
  { 
    if (j < 10)
      printf("PRO", j++);
    else
      continue;
    printf("coder");
  }
  return 0;
 }
 

Compile Error due to use of continue in for loop.
No compile error but it will run into infinite loop printing PRO.
No compile error and it'll print PROcoder 10 times followed by Quiz once.
No compile error and it'll print PROcoder 10 times.
Show Answer
Questions on C Quiz 4 : Question 5 :
Which of the following statement is correct for switch controlling expression?

Only int can be used in “switch” control expression.
Both int and char can be used in “switch” control expression.
All types i.e. int, char and float can be used in “switch” control expression.
“switch” control expression can be empty as well.
Show Answer