+ 1

Will this go to infinite loop?

#include<stdio.h> void main() { int a=0; while(a==0) { printf("hello"); } }

27th Aug 2018, 8:01 PM
athik
6 Answers
+ 3
loop repeats as long as loop condition( "a" being equal to 0) is met. Since "a" is initialized as 0, loop condition will be met and the loop is guaranteed to run at least once. At the end of a loop, condition is checked again, to repeat the loop if the condition is true. Since "a" remains unchanged (it remains 0), condition will be true, and the loop will run again. This will repeat infinitely
27th Aug 2018, 8:16 PM
Data
Data - avatar
+ 2
Data can you explain it, thank u
27th Aug 2018, 8:13 PM
athik
+ 2
athik rehman there is a joke about programmer A wife said to his husband while you are out buy some milk so he never came back (because there is no end condition how much milk) so is your loop it is always true and it will always run and loop always run until the condition become false hope you find it usefull
28th Aug 2018, 1:41 AM
Amir Ahmad
Amir Ahmad - avatar
+ 2
28th Aug 2018, 2:10 AM
Amir Ahmad
Amir Ahmad - avatar
+ 1
yes, "a" is never changed
27th Aug 2018, 8:03 PM
Data
Data - avatar
0
Amir Ahmad kya baat hyy iskeyliye waiting shukriya
28th Aug 2018, 2:09 AM
athik