练习4.28
int main()
{
//每一种内置类型所占空间的大小
cout << sizeof(bool) << endl; //1个字节
cout << sizeof(char) << endl; //1个字节
cout << sizeof(wchar_t) << endl; //2个字节
cout << sizeof(char16_t) << endl; //2个字节
cout << sizeof(char32_t) << endl; //4个字节
cout << sizeof(short) << endl; //2个字节
cout << sizeof(int) << endl; //4个字节
cout << sizeof(long) << endl; //4个字节
cout << sizeof(long long) << endl; //8个字节
cout << sizeof(float) << endl; //4个字节
cout << sizeof(double) << endl; //8个字节
cout << sizeof(long double) << endl; //8个字节
}
练习4.29
int main()
{
long x[10];
long* p = x;
//数组的大小除以单个元素的大小得到数组中元素的个数
cout << sizeof(x)/ sizeof(*x) << endl; //10
//指针所占的空间大小除以类型的空间大小
cout << sizeof(p) / sizeof(*p) << endl; //1
}
练习4.30
sizeof x + y;
(sizeof x) + y;
sizeof p->men[i];
sizeof (p->men[i]);
sizeof a < b;
(sizeof a) < b;
sizeof f();
sizeof (f());