C | C Quiz – 113 | Question 1

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
  
int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf("%d", i);
    return 0;
}

chevron_right


(A) Infinite Loop
(B) 0
(C) 1
(D) Run Time Error


Answer: (C)

Explanation: The result will be 1 but after a really long time because while loop will keep on going until i becomes 4294967295 (Assuming unsigned int is stored using 4 bytes) and as i highest limit of unsigned int is 4294967295 in next ++ operation it will become zero and we’ll come out of loop and 1 will be printed.

Since the time taken is long, on-line compiler may terminate the program with time limit exceeded error. If instead of unsigned int, you use unsigned short int then result (1) may come faster.

Quiz of this Question



My Personal Notes arrow_drop_up