Author Topic: The follwoing program fragment for (i = 1; i < 5; ++i)  (Read 273 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2271
    • View Profile
    • Engineering Forum
The follwoing program fragment for (i = 1; i < 5; ++i)
« on: March 07, 2017, 02:46:15 PM »
Advertisement
Question: The follwoing program fragment

for (i = 1; i < 5; ++i)
if (i ==3) continue;
else printf("%d ", i);


Results in the printing of?

Options are:


A. 1 2 4 5
B. 1 2 4
C. 2 4 5
D. None of the above

Correct answer is:

B. 1 2 4

Explanation


The use of continue statement forces the execution to skip the remainder of the current pass over the loop and initiates the next. If 'i' is 3, printf statement will be skipped.
hence the answer is B.


Engineering Forum

The follwoing program fragment for (i = 1; i < 5; ++i)
« on: March 07, 2017, 02:46:15 PM »

 

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: "mehran" without quotes: