int arr[5]
在典型情况下大小为 4 * 5 = 20
字节。int
相同,即4字节。在实际编程中,我们可以使用sizeof
运算符来获取不同数据类型的大小。以下是一个简单的示例代码:
#include <stdio.h>
int main() {
printf("Size of char: %lu bytes\n", sizeof(char));
printf("Size of short: %lu bytes\n", sizeof(short));
printf("Size of int: %lu bytes\n", sizeof(int));
printf("Size of long: %lu bytes\n", sizeof(long));
printf("Size of long long: %lu bytes\n", sizeof(long long));
printf("Size of float: %lu bytes\n", sizeof(float));
printf("Size of double: %lu bytes\n", sizeof(double));
printf("Size of long double: %lu bytes\n", sizeof(long double));
printf("Size of pointer: %lu bytes\n", sizeof(int*));
return 0;
}
Size of char: 1 bytes
Size of short: 2 bytes
Size of int: 4 bytes
Size of long: 4 bytes
Size of long long: 8 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of long double: 16 bytes
Size of pointer: 8 bytes
请注意,上述大小是通常情况下的一般规则,实际大小可能会受到编译器、操作系统和硬件架构的影响。因此,在编写代码时,要特别注意处理不同平台和编译器的差异,以确保代码的可移植性和性能。