Tuesday 23 April 2013

for loop example with semicolon.



What will be output if you will compile and execute the following c code?

void main(){
  int x;
  for(x=1;x<=5;x++);
    printf("%d",x);
}


(A) 4

(B) 5

(C) 6

(D) Compiler error

(E) None of above


________________________________________
Explanation: 6
Body of for loop is optional. In this question for loop will execute until value of variable x became six and condition became false.

No comments:

Post a Comment