tags:

views:

57

answers:

3

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

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

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

+1  A: 

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.

Justin Ethier
Er, isn't the really big problem the fact that the allocated memory is being typecast to a non-pointer type?
Jefromi
Without knowing what type `pData1` is, it is impossible to know if it is a non-pointer type.
Justin Ethier
Yeah, I see all the edits now. 's all good.
Jefromi
+1  A: 

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.

Steve314
A: 

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;

paquetp