#include<iostream>
using namespace std;



struct node
{
int a;
char b;
};

int main ()


{
cout<<sizeof(node)<<endl;
system("pause");
return 0;

}

這段代碼運(yùn)行后 您認(rèn)為應(yīng)該輸出幾呢?
上課的時(shí)候老師突然提出了這樣一個(gè)問題,當(dāng)時(shí)我想都沒想 直接回答了 5。
呵呵 答案當(dāng)然是錯(cuò)的 現(xiàn)在來運(yùn)行一下這個(gè)程序 發(fā)現(xiàn)這個(gè)程序的結(jié)果是8;
PS:感謝樓下兩位朋友的提問 讓問題變得更有意思了 內(nèi)部原理究竟是怎樣的呢?希望知道的朋友能夠予以解答
我在這里僅給出一些測(cè)試現(xiàn)象
struct node
{
};
輸出為1
struct node
{
char a;
};
輸出為1
struct node
{
int a;
double b;
};
輸出為16
struct node
{
char a;
char b;
char c;
char d;
char e;
}
輸出為5