0

Why is output 12 time repeat SoloLearn??

int i=2048; while(i){ printf("SoloLearn\n"); i>>=1; }

25th May 2020, 3:36 PM
Karan Dewangan
Karan Dewangan - avatar
2 Réponses
25th May 2020, 3:43 PM
HonFu
HonFu - avatar
0
Because look, a while with no condition but just a number will keep running as long as the number is not 0. Each loop you divide i by 2. In the 12th loop, i becomes less than 1 (a decimal) and as i is an integer it truncates the decimal and becomes zero. So loop stops
25th May 2020, 3:43 PM
Asirap