ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
int x = 10;
#else
int x = 20;
#endif
printf("%d", x);
  1. A. 10 on any conforming C99-or-later compiler, 20 otherwise
  2. B. Always 10, regardless of standard version
  3. C. Always 20, regardless of standard version
  4. D. Compile-time error: __STDC_VERSION__ is not a valid macro

Correct answer: A. 10 on any conforming C99-or-later compiler, 20 otherwise

This is a standard feature-detection idiom: __STDC_VERSION__ is a predefined macro reporting the C standard version the compiler is targeting (199901L for C99). On any modern compiler compiling as C99 or later, the condition is true and x=10; on a strict C89/ANSI-only compiler lacking that macro (or with a smaller value), the #else branch sets x=20.

More C Programming questions

Exams that ask this topic