Discussion
What will be the output of the program?
#include <stdio.h>
#define PRINT(int) printf("int=%d, ", int);
int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}
Answer: A
Correct answer: int=2, int=3, int=4
A macro parameter may be named int - the preprocessor has no reserved words, and within the macro body the name simply stands for whatever was passed. Each call substitutes its own argument, so the three calls print 2, 3 and 4. The int= inside the string literal is untouched, since macro replacement never reaches inside a string.
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