Preprocessor Directive MCQ 1 : Pre Incrementing Macro

January 26, 2025 No Comments » Hits : 161






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)

Incoming search terms:

You may like these articles :