用C语言写出一个验证基本数据类型的长度的代码
时间: 2024-05-12 10:13:37 浏览: 10
以下是一个验证基本数据类型长度的C语言代码:
```c
#include <stdio.h>
int main() {
printf("Size of char: %ld byte(s)\n", sizeof(char));
printf("Size of short: %ld byte(s)\n", sizeof(short));
printf("Size of int: %ld byte(s)\n", sizeof(int));
printf("Size of long: %ld byte(s)\n", sizeof(long));
printf("Size of long long: %ld byte(s)\n", sizeof(long long));
printf("Size of float: %ld byte(s)\n", sizeof(float));
printf("Size of double: %ld byte(s)\n", sizeof(double));
printf("Size of long double: %ld byte(s)\n", sizeof(long double));
return 0;
}
```
这个代码会输出每种基本数据类型的长度,例如:
```
Size of char: 1 byte(s)
Size of short: 2 byte(s)
Size of int: 4 byte(s)
Size of long: 8 byte(s)
Size of long long: 8 byte(s)
Size of float: 4 byte(s)
Size of double: 8 byte(s)
Size of long double: 16 byte(s)
```