Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

#include <stdio.h>
int main()
{
    unsigned int i = 65536; /* Assume 2 byte integer*/
    while(i != 0)
        printf("%d",++i);
    printf("\n");
    return 0;
}

 

  • A.Infinite loop
  • B.0 1 2 ... 65535
  • C.0 1 2 ... 32767 - 32766 -32765 -1 0
  • D.No output

Answer: D

Correct answer: No output

An unsigned int two bytes wide holds 0 to 65535, so the initialiser 65536 wraps round to 0. The condition i != 0 is false on the very first test, the loop body never runs, and the only thing printed is the newline.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.