+ 1
Why this program prints both true and false
#include <stdio.h> int main() { int a=1; if (a--) printf("true\n"); if (++a) printf("false"); return 0; }
1 Réponse
+ 11
a = 1;
if(a--) // here <a> is evaluated before decremented (<a> is still 1, thus considered true)
printf("true\n"); // here <a> has been decremented and becomes zero
if(++a) // here <a> is incremented and has become 1 before it is evaluated (yields true)
printf("false");
Ask away if it wasn't clear
Hth, cmiiw