Discussion
What will be the output of the following program?
#include <stdio.h>
void fun();
int main()
{
fun();
return 0;
}
void fun()
{
auto int i = 1;
register char a = 'D';
static int p = 0;
printf("%d %d %ld", i, a, p);
}
Answer: D
Correct answer: 1 68 0
Each declaration in fun behaves as its storage class says:
auto int i = 1;prints as 1.register char a = 'D';is printed with%d, not%c, so it comes out as the character’s code - 68 in ASCII.static int p = 0;prints as 0.
So the output is 1 68 0. The trap is the format specifier: a char is an integer type, and %d shows its numeric value.
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