1. 在32位平台上,有如下的输出是:
#include <iostream>
using namespace std;
void foo(char array4[10]){
cout << sizeof(array4) << endl;
}
int main(){
char array1[10] = "hello";
char array2[] = "hello";
char array3[2][3] = {"ab", "cd"};
char *p=array1;
cout << sizeof(array1) << endl;
cout << sizeof(array2) << endl;
cout << sizeof(array3) << endl;
cout << sizeof(p) << endl;
foo(array1);
}
2. 在Win32平台上,如下程序的输出是:
#include <iostream>
using namespace std;
struct MyStruct1{
char a;
int b;
};
struct MyStruct2{
int a;
char b;
};
struct MyStruct3{
int a;
char b;
double c;
};
struct MyStruct4{
char a;
MyStruct3 s3;
};
int main(){
cout << sizeof(MyStruct1) << endl;
cout << sizeof(MyStruct2) << endl;
cout << sizeof(MyStruct3) << endl;
cout << sizeof(MyStruct4) << endl;
}
【参考】
1. Struct 对齐问题:http://blog.csdn.net/lbjfeng/archive/2009/03/04/3952387.aspx