Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
Answer: D
Correct answer: JACK
Take the three prints in turn. ch is 74, the code for J, so the first prints J. Then j is 65 and *(int*)vp yields 65, which %c prints as A.
Finally vp is set to cp, and (char*)vp+2 advances two characters into "JACK", so %s prints CK. The three outputs concatenate to JACK - a coincidence engineered by the question rather than anything the code copies.
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