#include<stdio.h>
int main(){
int i=0;
while(i<4,5){
printf("loop");
i++;
}
}
This code goes infinite loop. can anyone explain logic behind these?
#include<stdio.h>
int main(){
int i=0;
while(i<4,5){
printf("loop");
i++;
}
}
This code goes infinite loop. can anyone explain logic behind these?
In the code
while(i<4,5)
is same as
while(5)
which is always true.
As per the comma operator properties, quoting from C11
, chapter 6.5.17/P2
The left operand of a comma operator is evaluated as a void expression; there is a sequence point between its evaluation and that of the right operand. Then the right operand is evaluated; the result has its type and value
Point to note: With this code, you'll hit undefined behaviour due to signed overflow in i++
.