Author Topic: The following program fragment for (i = 3; i < 15; i += 3); printf("%d", 1);  (Read 257 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2255
    • View Profile
    • Engineering Forum
Advertisement
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.

Engineering Forum


 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
type: "Pakistan" without quotes: