#include <stdio.h> #include <conio.h> int main() { int test[5] = {0}; printf("the size of char is %d byte\n", sizeof(char)); printf("the size of int is %d byte\n", sizeof(int)); printf("the size of float is %d byte\n", sizeof(float)); printf("the size of double is %d byte\n", sizeof(double)); printf("the size of long is %d byte\n\n", sizeof(long)); for (int i = 0; i < sizeof(test)/sizeof(int); i++) { printf("the address of test[%d] is: %x\n",i,&test[i]); } getch(); }
从输出的数组元素地址可以看出 数组是一块连续的内存区域,并且本例子是以整形数组为例,元素之间地址相差4,刚好是一个整形变量的大小(4字节)
时间: 2024-10-07 21:31:55