Discussion
Predict the output of following program?
#include <stdio.h>
#define MAX 1000
int main()
{
int MAX = 100;
printf("%d ", MAX);
return 0;
}
Answer: C
Correct answer: Compiler Error
The macro replaces the identifier MAX everywhere it appears, including in the declaration. The compiler therefore sees
int 1000 = 100;
which is a syntax error. The preprocessor knows nothing about scope or declarations - it is a text substitution, and this is why macro names are conventionally written in capitals, so they are not accidentally reused as variable names.
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