为什么第一种情况下不是12?测试:最新版本的gcc和clang,64位Linux
struct desc
{
int** parts;
int nr;
};
Run Code Online (Sandbox Code Playgroud)
sizeof(desc); Output: 16
struct desc
{
int** parts;
};
Run Code Online (Sandbox Code Playgroud)
sizeof(desc); Output: 8
struct desc
{
int nr;
};
Run Code Online (Sandbox Code Playgroud)
sizeof(desc); Output: 4
#include <iostream>
using namespace std;
struct test
{
int i;
double h;
int j;
};
int main()
{
test te;
te.i = 5;
te.h = 6.5;
te.j = 10;
cout << "size of an int: " << sizeof(int) << endl; // Should be 4
cout << "size of a double: " << sizeof(double) << endl; //Should be 8
cout << "size of test: " << sizeof(test) << endl; // Should be 24 (word size of 8 for double)
//These two …Run Code Online (Sandbox Code Playgroud)