使用C中的sizeof进行数组分配的问题

时间:2013-11-23 19:47:29

标签: c arrays allocation corruption

mid= n / 2;//(where n is 10)

int left[sizeof(mid)];

但是编译器为4 [0,1,2,3]个元素分配空间,它假设分配5 [0,1,2,3,4]个元素。

可能是什么问题?

1 个答案:

答案 0 :(得分:3)

sizeof表示:内存中的大小。 int是内存中的4个字节。所以sizeof(int)= 4。

你可能想写int left[mid];