int main(int argc, const char * argv[])
{
int numbers[3];
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
printf("sizeof(numbers) is = %lu\n",sizeof(numbers));
printf("sizeof(numbers[0])is = %lu\n",sizeof(numbers[0]));
for (int i= 0; i<sizeof(numbers)/sizeof(numbers[0]); i++)
{
printf("numbers[%d] = %d\n",i,numbers[i]);
}
return 0;
}
sizeof(numbers) is = 12
sizeof(numbers[0]) is = 4
numbers[0] = 1
numbers[1] = 2
numbers[2] = 3
虽然只初始化了第一个元素,但其他元素也同时初始化为0了。
sizeof(numbers) ,得到数组中所有元素长度之和
sizeof(numbers[0]),得到一个元素的大小