What is the output of this C code?
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
int **sptr = &ptr1; //-Ref
*sptr = ptr2;
}
Answer: B
Correct answer: ptr1 points to b
sptr holds the address of ptr1, so *sptr is ptr1, and assigning ptr2 to it copies the address of b into ptr1. Afterwards ptr1 and ptr2 both point at b. Note that sptr itself is unchanged and still points at ptr1.
Please log in or register to report this question.