Test Code:
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 struct A{ 7 int a; 8 short b; 9 char d; 10 char e[10]; 11 }; 12 13 struct B{ 14 int a; 15 short b; 16 char *c; 17 char d; 18 char e[10]; 19 }; 20 21 int main(){ 22 23 cout<<sizeof(A)<<endl; 24 cout<<sizeof(B)<<endl; 25 cout<<"short "<<sizeof(short)<<endl; 26 cout<<"int "<<sizeof(int)<<endl; 27 cout<<"long "<<sizeof(long)<<endl; 28 cout<<"char* "<<sizeof(char*)<<endl; 29 30 return 0; 31 32 }
Output(Fedora 64bit):
20 32 short 2 int 4 long 8 char* 8
时间: 2024-10-11 10:20:30