+ 1

Loop structure c

Could someone explain the answer (12) in the quiz question below: How may times will “Sololearn” be printed in this statement below? int i = 2048; While (i) { printf(“Sololearn\n”); i >= 1; }

1st Oct 2020, 11:21 AM
Joe Bosah
3 Antworten
+ 1
i>>=1 here it means i = i >>1, >> right shift operator.. After first iteration, i = 1024 Next I = 512, => 256 => 128 => 64 => 32 => 16 => 8 => 4 => 2 => 1 => 0 Total 12 times loop runs. Edit : see this for more.. Joe Bosah https://www.sololearn.com/learn/4086/?ref=app
1st Oct 2020, 11:32 AM
Jayakrishna 🇮🇳
+ 1
thank you so much
1st Oct 2020, 11:33 AM
Joe Bosah
+ 1
You're welcome..
1st Oct 2020, 11:36 AM
Jayakrishna 🇮🇳