C中调用函数之前的参数求值顺序在C中调用函数参数时,可以假定函数参数的赋值顺序吗?根据下面的程序,当我执行它时,似乎没有一个特定的命令。#include <stdio.h>int main(){
int a[] = {1, 2, 3};
int * pa;
pa = &a[0];
printf("a[0] = %d\ta[1] = %d\ta[2] = %d\n",*(pa), *(pa++),*(++pa));
/* Result: a[0] = 3 a[1] = 2 a[2] = 2 */
pa = &a[0];
printf("a[0] = %d\ta[1] = %d\ta[2] = %d\n",*(pa++),*(pa),*(++pa));
/* Result: a[0] = 2 a[1] = 2 a[2] = 2 */
pa = &a[0];
printf("a[0] = %d\ta[1] = %d\ta[2] = %d\n",*(pa++),*(++pa), *(pa));
/* a[0] = 2 a[1] = 2 a[2] = 1 */}
3 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
函数指示符、实际参数中的实际参数和子表达式的计算顺序未指定,但在实际调用之前有一个序列点。
pa
$ gcc -Wall -W -ansi -pedantic test.c -o test test.c: In function ‘main’:test.c:9: warning: operation on ‘pa’ may be undefined test.c:9: warning: operation on ‘pa’ may be undefined test.c:13: warning: operation on ‘pa’ may be undefined test.c:13: warning: operation on ‘pa’ may be undefined test.c:17: warning: operation on ‘pa’ may be undefined test.c:17: warning: operation on ‘pa’ may be undefined test.c:20: warning: control reaches end of non-void function
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
int i=1;printf("%d %d %d\n", i++, i++, i);
2 1 3
1 2 3
2 1 3
1 2 3
1 2 3
1 2 3
- 3 回答
- 0 关注
- 572 浏览
添加回答
举报
0/150
提交
取消