Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么这个程序以这种方式运行?_C_Arrays_Addition - Fatal编程技术网

C 为什么这个程序以这种方式运行?

C 为什么这个程序以这种方式运行?,c,arrays,addition,C,Arrays,Addition,x打印为3,但我希望它返回2?事实上,如果我删除++并将x设置为a[1],它将返回为2。它为实际存在的任何值加1。我错过什么了吗 x打印为3,但我希望它返回2 此处x=2,因为预增量 你所拥有的 x = ++a[1]; x = ++a[1];//Increment a[1] and then assign it to x y = a[1]++;//assign a[1] to y and then increment a[1] z = a[x++];//assign a[2] to z a

x打印为3,但我希望它返回2?事实上,如果我删除++并将x设置为a[1],它将返回为2。它为实际存在的任何值加1。我错过什么了吗

x打印为3,但我希望它返回2

此处x=2,因为预增量

你所拥有的

 x = ++a[1]; 
x = ++a[1];//Increment a[1] and then assign it to x
y = a[1]++;//assign a[1] to y and then increment a[1]
z = a[x++];//assign a[2] to z and then increment x
因此x=3

x打印为3,但我希望它返回2

此处x=2,因为预增量

你所拥有的

 x = ++a[1]; 
x = ++a[1];//Increment a[1] and then assign it to x
y = a[1]++;//assign a[1] to y and then increment a[1]
z = a[x++];//assign a[2] to z and then increment x
因此x=3

该++称为增量运算符。它将值增加1。 在你的代码中你有

 x = ++a[1]; 
x = ++a[1];//Increment a[1] and then assign it to x
y = a[1]++;//assign a[1] to y and then increment a[1]
z = a[x++];//assign a[2] to z and then increment x
++变量之前是预增量运算符。在将a[1]的值指定给x之前,它会递增该值。所以a[1]和x的值变为3

另一个

x = ++a[1];
++变量后面是后增量运算符。它将已经变为3的[1]赋值给y,然后将[1]的值增加到4

此链接将帮助您

将++称为增量运算符。它将值增加1。 在你的代码中你有

 x = ++a[1]; 
x = ++a[1];//Increment a[1] and then assign it to x
y = a[1]++;//assign a[1] to y and then increment a[1]
z = a[x++];//assign a[2] to z and then increment x
++变量之前是预增量运算符。在将a[1]的值指定给x之前,它会递增该值。所以a[1]和x的值变为3

另一个

x = ++a[1];
++变量后面是后增量运算符。它将已经变为3的[1]赋值给y,然后将[1]的值增加到4

此链接将帮助您

在这方面,

x=++a[1]; //  Now x got the value 2. 
它是后增量,因此z的值为15。参考这个

在这方面,

x=++a[1]; //  Now x got the value 2. 

它是后增量,因此z的值为15。请参阅。

阅读一本关于C编程的好书。关注@BasileStarynkevitch:与序列点无关:这里的一切都是正确排序的。阅读一本关于C编程的好书。关注@BasileStrynkevitch:与序列点无关:这里的所有内容都已正确排序。