我正在学习编程,从C语言开始。我正在阅读《让我们一起学C语言》这本书,并且在浏览其中的一个程序。
main( )
{
int a[5] = { 5, 1, 15, 20, 25 } ;
int i, j, k = 1, m ;
i = ++a[1] ;
j = a[1]++ ;
m = a[i++] ;
printf ( "\n%d %d %d", i, j, m ) ;
}
我的理解是,它将打印i为2
, j为1
和m为15
但不知何故,它却打印为i为3
,j为2
和m为15
?为什么会这样呢?
以下是我的理解-
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.
我对理解是否有误,还请指教。