Does memory allocation for pointer is same in both scenarios
struct_datatype * p=NULL;
struct_datatype * p=malloc;
apart from memory allocation from stack and heap ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The question is not clear what you are asking about.
struct_datatype * p=NULL;No memory has been assigned to
p. It points to no allocated memory.struct_datatype * p=malloc();Some memory might have been allocated and the address of the memory allocated has been assigned to
p. If malloc failed NULL would have been assigned top.NOTE: sizeof
pwill be sizeofstruct_datatype*for both the cases.NOTE: The pointer variable
pwill have been assigned memory in the stack which is sizeofstruct_datatype*in both the cases during compile time. The address stored in pointerpmight be pointing to any valid memory address accessible in user address space. In theNULLcase no address is assigned( and NULL is not user accessible address) but when you domalloc(if successful) the address of the memory allocated will be assigned to the pointerpfrom the heap space else again it will be assigned to NULL.