我们使用下面的结构.
struct S
{
int i;
int *p;
};
Run Code Online (Sandbox Code Playgroud)
主要流程:
int main()
{
S s;
int *p = &s.i;
p[0] = 4;
p[1] = 3;
printf("p[0]=%d\n", p[0]);
printf("p[1]=%d\n", p[1]);
s.p = p;
s.p[0] = 1;
s.p[1] = 2;
printf("p[0]=%d\n", p[0]);
printf("p[1]=%d\n", p[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我们的进程运行它在sp [1] = 1时发生了内存错误,当我们用Visual C++编译它时.
但是当我们用GCC编译它时它可以运行.
为什么在VC++中出现错误但GCC没有?
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |