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; }
Options :
- 10
- 11
- Compile Error
- Run-time Error
Compile 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/decrement operators should be used with variable)
Incoming search terms:
- mcq on preprocessor macro substitution (2)
- mcq error/output in c (1)
- mcq on c programming preprocessor (1)