Discussion
What is the output of this C code?
#include <stdio.h>
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
Answer: D
Correct answer: 11,11
ptr holds the address of a, so *ptr and a are two names for the same object. *ptr += 1 increments that object, and both expressions therefore read 11.
Note the format string ends in /n, a forward slash, not the escape \n. So the two characters are printed literally and no newline is emitted - a typographical slip that changes the output's appearance without affecting the values, which are what the question asks for.
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