In C,
int i = 20;
int j = 5;
int k = i+++--j;
Why is k=24?
In my understanding, k = (i)++ + (--j) so it is (20 + 4)++ = 25.
OK. Here is a little programme I wrote for test, and yes the post increment is done after k is assigned.
#include <stdio.h>
int main()
{
int i = 20;
int k = i++;
printf("%d
", k);
printf("%d
", i);
return 0;
}
Output:
20
21
Could anyone tell me why vote down? I was unsure about this because I was a new commer to C.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…