Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ sizeof(结构)。。。给出错误的结果,VS 2010 struct测试{ 国际年; 字符文本; 双数; }; int main() { 试验t; cout_C++_Structure_Sizeof - Fatal编程技术网

C++ sizeof(结构)。。。给出错误的结果,VS 2010 struct测试{ 国际年; 字符文本; 双数; }; int main() { 试验t; cout

C++ sizeof(结构)。。。给出错误的结果,VS 2010 struct测试{ 国际年; 字符文本; 双数; }; int main() { 试验t; cout,c++,structure,sizeof,C++,Structure,Sizeof,C++可能会在成员之间添加填充。因此,结构可能大于其成员的添加大小。double将以mem-aligned(字大小)存储。如果编译器给出的答案与您期望的不符,则通常不是编译器出错。 struct test{ int year; char text; double num; }; int main () { test t; cout<<sizeof(t); return 0; }

C++可能会在成员之间添加填充。因此,结构可能大于其成员的添加大小。

double
将以mem-aligned(字大小)存储。如果编译器给出的答案与您期望的不符,则通常不是编译器出错。
struct test{
    int year;
    char text;
    double num;
};

int main ()
{

 test t;
 cout<<sizeof(t);
  return 0;
}