Preprocessor Directive MCQ 1 : Pre Incrementing Macro
Guess What will be the output of following Code Snippet -
#include<stdio.h> #define MAX 10 int main(){ int num; num = ++MAX; printf("%d",num); return 0; }
No | Options |
---|---|
A | 10 |
B | 11 |
C | Compile Error |
D | Run Time Error |
Explanation :
num = ++MAX; will be expanded as - num = ++10; = Compile Error
- Macro Preprocessor only replaces occurance of macro symbol with macro symbol value
- Preprocessor replace MAX with 10.
Expanded Program :
int main(){ int num; num = ++10; printf("%d",num); return 0; }
- Above expanded code is now given to compiler
- Compiler will throw error : Lvalue Require Error. (because Increment Operator and Decrement Operators should be used with variable)