Code
int main() {
int cnt = 5;
while(cnt > 0) {
printf("cnt = %d %s\n", --cnt, (cnt == 0) ? "cnt == 0" : "cnt != 0");
}
return 0;
}
My Expected Output
cnt = 4 cnt != 0
cnt = 3 cnt != 0
cnt = 2 cnt != 0
cnt = 1 cnt != 0
cnt = 0 cnt == 0
Real Output
cnt = 4 cnt != 0
cnt = 3 cnt != 0
cnt = 2 cnt != 0
cnt = 1 cnt != 0
cnt = 0 cnt != 0
I think when cnt = 1 after --cnt, cnt will have new value 0, and the test cnt == 0 will be true, but the real result isn't what I expect, why?