第1个回答 2011-11-02
void *calloc( size_t num, size_t size );
Return Value
calloc returns a pointer to the allocated space. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.
Parameters num--------Number of elements
size----------Length in bytes of each element
p=(int*)calloc(n,2);
指有是有n个元素,每个元素占2个字节。这个地方要是16位机的话int是2个字节,现在的一般是32位机所以int是4个字节,p=(int*)calloc(n,2);改为p=(int*)calloc(n,4);
p=(int*)calloc(3,sizeof(int));
指有是有3个元素,每个元素占sizeof(int)=4个字节。本回答被提问者采纳