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 :

  1. 10
  2. 11
  3. Compile Error
  4. 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)