Programming in C - Decision Making and Looping

21. The following program fragment
int i = 5;
do
{
putchar(i + 100);
printf("%d", i--);
}
while (i);
results in the printing of

  • Option : A
  • Explanation :
    putchar (1 0 5) 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.
Cancel reply
Cancel reply

22. The following loop
while(printf("%d", printf("az")))
printf("by");

  • Option : D
  • Explanation :
    printf("az") prints az and returns a value 2 (since it printed two characters). So. the condition results in the printing of az2. Since it always returns 2, it is an infinite loop. The output will be az2byaz2by...
Cancel reply
Cancel reply