|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- struct ks
- {
- int a;
- int *b;
- }s[4],*p;
- int main()
- {
- int n=1,i;
- printf("\n");
- for(i=0;i<4;i++)
- {
- s[i].a=n;
- s[i].b=&s[i].a;
- n=n+2;
- }
- p=&s[0];
- p++;
- printf("%d,%d\n",(++p)->a,(p++)->a);
- return 0;
- }
复制代码
为啥输出7,3?
本帖最后由 jackz007 于 2022-10-16 17:20 编辑
gcc 编译、运行:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- D:\[00.Exerciese.2022]\C>x
- 7,3
复制代码
使用 VC 6.0 编译、运行:
- D:\[00.Exerciese.2022]\C>cl x.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
- Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
- x.c
- Microsoft (R) Incremental Linker Version 6.00.8447
- Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
- /out:x.exe
- x.obj
- D:\[00.Exerciese.2022]\C>x
- 5,3
- D:\[00.Exerciese.2022]\C>
复制代码
就是说:
【gcc】:
【VC6.0】:
可见,结果因编译器而异,这种问题不适合讨论。
如果不想自找麻烦,劝楼主不要写这样的代码。
|
|