What is the output of this C code?
int x = 0;
void main()
{
int *ptr = &x;
printf("%p\n", ptr);
x++;
printf("%p\n ", ptr);
}
Answer: A
Correct answer: Same address
Incrementing x changes the value stored at the address, not the address itself, and ptr was never modified. So both %p conversions print the same thing. The question is testing that a pointer and the object it points to are separate: assigning through the pointer alters one, assigning to the pointer alters the other.
Please log in or register to report this question.