Can anyone who can explain why these code output 1, so much appreciation !! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone who can explain why these code output 1, so much appreciation !!

#include<string.h> #include<stdio.h> enum{TRUE,FALSE}; int main(){ int x = 1; do{ printf("%d",x); x++; if(x>5) break; }while(TRUE); return 0; }

29th Jul 2022, 3:08 AM
范祥彥
范祥彥 - avatar
4 Answers
+ 6
范祥彥 there is a little trick in the enum. By default, enum begins numbering values at zero. By defining TRUE first, it sets TRUE=0. The do/while loop is looking for any non-zero value to continue, but it encounters a zero right away, so it exits after one time through the loop.
29th Jul 2022, 3:25 AM
Brian
Brian - avatar
+ 2
范祥彥 Most of the quiz questions are posted by community members not by Sololearn so there is no explanation.
29th Jul 2022, 6:03 AM
A͢J
A͢J - avatar
+ 1
A͢J Got it, I can totally relate it. And maybe the strength of community is one of the reason why Sololearn stands out from other coding learning platform, once I step into here I was fascinated, because of knowing that I am not alone on the road, it always motivates me to keep learning.
29th Jul 2022, 6:43 AM
范祥彥
范祥彥 - avatar
0
Brian Thank you so much! It is weird that the challenge give the answer but no explanation, hopefully the community has many enthusiastic professional just like you! Thank you again and wish you have a nice day.
29th Jul 2022, 5:18 AM
范祥彥
范祥彥 - avatar