c - while loop and arithmetic operator -
int = 5; while(i>5) printf("%d",i); prints nothing.
int = 5; while ( 5<i<10 ) { printf("%d",i); i++; } prints 5
in both cases shouldn't result "prints nothing" . because 5 not less 5.
in c integer used boolean: 0 false, else true. @jonathanleffler noted (see comment below), in c99 , c11 there standard boolean datatype, expands integer constants (0 , 1). link.
when write expression 5 < < 10, treated (5 < i) < 10, 5 < i boolean expression, returns 0. (0) < 10, true, that's why loop's body executed. in order make loop condition correct, shoould use like:
while (5 < && < 10)
Comments
Post a Comment