#include "stdafx.h"
#include "iostream"
using namespace std;
struct S
{
int i = 10;
int *p = (int*)1111;
};//size of it is 16.
int main()
{
S s;
int *p = &s.i;
cout <<"size of s:"<< sizeof(s) << endl;
cout << "size of p[0]:"<<sizeof(p[0]) << endl;
cout<<"sizeof p:"<<sizeof(p) << endl;
cout << sizeof(s.p[0]) << endl;
p[0] = 4;
p[1] = 3;
s.p = p;
s.p[1] = 1;
s.p[0] = 2;
return 0;
}
本文通过一段示例代码探讨了在X64与X86不同架构下,指针操作及内存布局的区别。指出在X86平台下,由于内存布局的原因,对指针进行特定操作可能会导致程序错误。
980

被折叠的 条评论
为什么被折叠?



