Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
Answer: A
Correct answer: ink
Work outward. ptr holds {s+3, s+2, s+1, s}, and p = ptr then ++p leaves p pointing at ptr[1], which is s+2.
So *p is s+2, and **p is s[2], the pointer to "pink". Finally **p+1 advances that char pointer one position, so printf starts from the second character and prints ink. The trap is applying the +1 at the wrong level - it binds to the char pointer, not to p.
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