为什么函数sizeof在struct自身使用时不会返回相同的大小?
因为我正在努力的winsock程序,我需要抛出它.谢谢你的帮助,真的.
#include <iostream>
#include <string>
using namespace std;
struct stringstruct
{
string s1;
string s2;
};
int main()
{
stringstruct ss = {"123","abc"};
char *NX = (char*)&ss;
cout << sizeof(NX) << endl << sizeof(*NX) << endl;
cout << sizeof(&ss) << endl << sizeof(ss) << endl;
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的例子输出
4
1
4
64
Run Code Online (Sandbox Code Playgroud)