开发者

What's the difference of pData1 and pData2, which are build as follows

What's the difference of pData1 and pData2, which are build as follows:

pData1 = (int*) calloc (i,siz开发者_开发知识库eof(int));

int * pData2 = (int*) calloc (i,sizeof(int));


Without any more information, it would appear the only difference is that pData2 is local to the allocation since it is declared as an int *. pData1 is not declared so it would have to have a larger (global?) scope and be defined elsewhere.


The first is (presumably) an assignment to an already-existing variable named "pData1".

The second declares a new variable named "pData2", and initialises it.

Other than that, I don't see any difference.


Assuming pData1 is a pointer (int*), it can be dereferenced with *, and points to an int who's value is 0. pData2 will point to a new int also, who's value is zero, but cannot be dereferenced without casting to a pointer first, with something like:

*(int*)(pData2) = 4;

ie: you can't change/get the value the pData2 points to with something like *pData2 = 4;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜