The following program fragment for (i = 3; i < 15; i += 3); printf("%d", 1);

  • 0 replies
  • 705 views
*

Offline mechanic

  • *****
  • 2552
    • View Profile
    • Engineering Forum
Question: The following program fragment for

(i = 3; i < 15; i += 3);
printf("%d", 1);


results in

Options are:


A. a syntax error
B. an execution error
C. Printing of 12
D. printing of 15

Correct answer is:

D. printing of 15

Explanation:

'i' is initialized to 3, and incremented by 3. when i is 15, control will go out of the loop, so 15 will be printed. (the empty semi-colon immediately following the 'for' statement means the body of the for loop is empty.