#define a 10 int main() { #define a 50 printf("%d",a); getchar(); return 0; }

#define a 10

int main()

{

#define a 50

printf("%d",a);

getchar();

return 0;

}

Answer: C. 50The C preprocessor performs macro substitution before compilation begins. When an object-like macro is redefined with a different replacement text and no…

  1. A.

    10

  2. B.

    60

  3. C.

    50

  4. D.

    error

Attempted by 42 students.

Show answer & explanation

Correct answer: C

The C preprocessor performs macro substitution before compilation begins. When an object-like macro is redefined with a different replacement text and no #undef precedes it, the C standard requires only a diagnostic — most compilers, including GCC, satisfy this with a WARNING and still compile successfully, updating the macro to the newest definition.

  1. The identifier a is first defined as 10, outside main.

  2. Inside main, a is redefined as 50 before it is used anywhere in the code.

  3. Because the printf call appears after this second #define, the preprocessor substitutes a with the text of the LATEST definition seen up to that point — not the first one.

  4. The compiler emits a 'redefined' warning for the differing macro but still completes compilation and produces a running program.

GCC's own documentation on "Undefining and Redefining Macros" confirms this exact behaviour: a non-identical redefinition issues a warning and the preprocessor switches to the new definition — the build does not fail, and the substituted value is the most recent one. This matches the printed output.

Output: 50

Explore the full course: Accenture Preparation

Loading lesson…