Machine-translated by Google. Questions are authored in English.
Top

Discussion

What substitution should be made to //-Ref such that ptr1 points to variable C?

int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a;
int **sptr = &ptr1;
//-Ref
}

 

  • A.*sptr = &c;
  • B.**sptr = &c;
  • C.*ptr1 = &c;
  • D.None of the mentioned.

Answer: A

Correct answer: *sptr = &c;

*sptr is another name for ptr1, so assigning the address of c to it makes ptr1 point at c. The alternative **sptr = &c; would assign a pointer to the int that ptr1 currently points at, and *ptr1 = &c; does the same thing - both are type errors and both write to a rather than redirecting the pointer.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.