用c++写代码:用 sizcol 操作符求出表 2-2 中各数据类型的字节长度,并按 size of char1 bytesize of int2 byte 的格式打印输出
时间: 2024-05-04 07:17:54 浏览: 27
c++查看各类型字符的数据长度
```c
#include <stdio.h>
int main() {
printf("size of char: %ld byte\n", sizeof(char));
printf("size of int: %ld bytes\n", sizeof(int));
printf("size of float: %ld bytes\n", sizeof(float));
printf("size of double: %ld bytes\n", sizeof(double));
return 0;
}
```
输出:
```
size of char: 1 byte
size of int: 4 bytes
size of float: 4 bytes
size of double: 8 bytes
```
阅读全文