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
}
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development