Author Topic: The following program fragment int i = 5; do {putchar{i + 100}; printf{"%d", i--  (Read 500 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2316
    • View Profile
    • Engineering Forum
Advertisement
Question: The following program fragment

int i = 5; do {putchar{i + 100}; printf{"%d", i--};}
while {i};


results in the printing

Options are:


A. i5h4g3f2el
B. i4h3g2fle0
C. an error message
D. None of the above

Correct answer is:

A. i5h4g3f2el

Explanation:

putchar {105} will print the ASCII equivalent of 105 i.e 'i'. The printf statement prints the current value of i, i.e, 5 and then decrements it. So, h4 will be printed in the next pass, this continues until 'i' becomes 0, at which point the loop gets terminated.

Engineering Forum



Qirat

  • Guest

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:
2+2: