ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
#define N 5
#undef N
#define N 10
printf("%d", N);- A. 10
- B. 5
- C. Compilation error: N redefined
- D. 15
Correct answer: A. 10
#undef removes the previous definition of N before the second #define installs the new one, so by the time printf expands, N is 10, with no redefinition conflict.
More C Programming questions
- What is printed? c #if defined(DEBUG) #define LOG(msg) printf("DEBUG: %sn", msg) #else #define LOG(msg) #endif int main(void) {…
- What is printed? c #define VERSION 2 #if VERSION >= 2 const char msg = "new"; #else const char msg = "old"; #endif int main(void) {…
- What is printed? c #define TWICE(x) (2 (x)) #define FOURTIMES(x) TWICE(TWICE(x)) printf("%d", FOURTIMES(3));
- What is printed? c #define ISEVEN(n) ((n) % 2 == 0) int a = 7; printf("%d", ISEVEN(a + 1));
- What is printed? c #define EMPTY #define SEMI ; int x = 5 EMPTY SEMI printf("%d", x);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int value = 42; PRINT(value); }