sizeof 接受的参数可以是对象也可以是表达式,但是sizeof(expression) 在运行时==不会对接受的表达式进行计算==,编译器只会推导==表达式的类型==从而计算占用的字节大小;
```cpp
#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
int x = 4;
sizeof(x++);
printf("%d\n", x);//4
return 0;
}
```
1,由于 C 语言没有 bool 类型,用整形表示布尔型,因此下面的程序返回 4;
```c
#include<stdio.h>
void main(){
printf("%d\n", sizeof(1==1));
}
/*
运行结果:
4
*/
```
2,由于 C++ 语言有 bool 类型,布尔型占 1 个字节,因此下面的程序返回 1;
```cpp
#include <iostream>
using namespace std;
int main() {
cout << sizeof(1==1) << endl;
return 0;
}
/*
1
*/
```