{
int *p=12;
printf("%p",p);
printf("\n%d",p);
}
OUTPUT:
0000000C
12
Question: So is p assigned the address 0x0000000C?
{
int *p=12;
*p=22;
}
But this one doesn’t run. So what’s actually happening?
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.
This declares a pointer and sets the address to which it points to
12.This de-references the pointer and writes 22 to the
intat that memory address12. Since you did not allocate any memory and just set the pointer to point at a random address, it results in a runtime error.What is confusing you is that both pieces of code contain
*p=.... However, the first assignment is to the pointer, and the second assignment is to the pointee. This is just one of those notational overloadings that you have to get used to when programming in C.