ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
#define EMPTY
#define SEMI ;
int x = 5 EMPTY SEMI
printf("%d", x);- A. 5 (EMPTY expands to nothing and SEMI supplies the terminating semicolon)
- B. Compilation error: missing semicolon
- C. 0
- D. Compilation error: EMPTY cannot be used mid-statement
Correct answer: A. 5 (EMPTY expands to nothing and SEMI supplies the terminating semicolon)
EMPTY expands to nothing, so 'int x = 5 EMPTY SEMI' becomes 'int x = 5 ;' once SEMI expands to its literal semicolon — a valid, if unusual, declaration. x is 5.
More C Programming questions
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int value = 42; PRINT(value); }
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) int calls = 0; int next(void) { calls++; return calls; } int main(void) { int…
- What is printed? c #if defined(DEBUG) const int mode = 1; #else const int mode = 0; #endif int main(void) { printf("%d", mode); }
- What is printed? c #define ISODD(x) (x % 2 == 1) int main(void) { printf("%d", ISODD(4 - 1)); }
- What is printed? c #define STR(x) #x #define XSTR(x) STR(x) #define VERSION 7 int main(void) { printf("%s %s", STR(VERSION)…
- What is printed? c #define SWAP(a, b) do { int t = a; a = b; b = t; } while (0) int main(void) { int x = 1, y = 2; if (x < y) SWAP(x, y)…