|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int z[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0};
int main(void)
{
int j, n = 0;
for (j = 0; j < 11; j++)
{
printf("z[%d] = %d ", n++, z[n]);
if (10 == z[n])
{
j++;
printf("z[%d] = %d, j = %d\n", n, z[n], j);
break;
}
}
printf("z[%d] = %d, z[%d] = %d, z[%d] = %d, %d", n, z[n], n - 1, z[--n], n, z[n++], n);
_getch();
return 0;
}
/*VC6下运行结果
z[0] = 1 z[1] = 2 z[2] = 3 z[3] = 4 z[4] = 5 z[5] = 6 z[6] = 7 z[7] = 8 z[8] = 9
z[9] = 10, j = 9
z[8] = 9, z[7] = 9, z[9] = 10, 9
*/
/*期待结果
z[0] = 1 z[1] = 2 z[2] = 3 z[3] = 4 z[4] = 5 z[5] = 6 z[6] = 7 z[7] = 8 z[8] = 9
z[9] = 10, j = 9
z[9] = 10, z[8] = 9, z[8] = 9, 10
*/
//求解答,谢谢。
本帖最后由 jackz007 于 2022-11-14 22:03 编辑 #include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int z[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0};
int main(void)
{
int j, n = 0;
for (j = 0; j < 11; j++)
{
printf("z[%d] = %d ", n ++ , z[n]) ;
if (10 == z[n])
{
j++;
printf("z[%d] = %d, j = %d\n", n, z[n], j);
break;
}
}
printf("z[%d] = %d, z[%d] = %d, z[%d] = %d, %d" , n , z[n] , n - 1 , z[n - 1] , n - 1 , z[n - 1] , n + 1) ;
getch() ;
return 0 ;
}
同一个函数里同一个变量作为多个参数多次进行自加、自减操作,属于非确定性运算(第20行),其结果会因编译器的不同而有所不同,所以,必须极力避免这样使用。
|
|