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);- A. 10 on any conforming C99-or-later compiler, 20 otherwise
- B. Always 10, regardless of standard version
- C. Always 20, regardless of standard version
- 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
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define CLAMP(x, lo, hi) MIN(MAX(x, lo), hi) #define MAX(a, b) ((a) > (b) ?…
- What is printed? c #define INCR(x) (++x) int arr[3] = {10, 20, 30}; int i = 0; printf("%d", arr[INCR(i)]);
- What is printed? c #define ISEVEN(n) (((n) % 2) == 0) int main(void) { int x = 7; if (ISEVEN(x)) printf("even"); else printf("odd"); }
- What happens when this runs? c int x; printf("%d", x);
- What happens when this runs? c char p; { char buf[20] = "hello"; p = buf; } printf("%s", p);
- What happens when this runs? c int a[5] = {1, 2, 3, 4, 5}; a[5] = 100; printf("%d", a[5]);