What does this statement mean?
//allocated memory for Device info
(*PppsCoreStructure)->psDeviceDetails=(sDeviceDetails **)calloc(CORE_DEVICEINFO_SIZE, sizeof(sDeviceDetails*));
I know that '(*PppsCoreStructure)->psDeviceDetails' is a pointer to pointer. But I am not being able to imagine how calloc can return pointer to pointer? I'm a beginner please help
Answer
(*PppsCoreStructure)->psDeviceDetails
is declared with typesDeviceDetails **
- The return value of
calloc()
is of typevoid*
(sDeviceDetails **)calloc(...)
casts the return value ofcalloc
to be of typesDeviceDetails **
In the C++ language this type cast is essential, although in C++ one would normally not be using calloc
and would probably be using C++ casts.
In the C language the type cast is not needed because a void*
pointer is assignment compatible with all other pointer types.
In a comment you state
But I want know how
sDeviceDetails*
is different fromsDeviceDetails**
and I suspect that this is in fact your real question.
The answer is simple enough: T*
is a pointer-to-T and T**
is a pointer-to-pointer-to-T.
No comments:
Post a Comment