ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
#define PRINT(x) printf(#x " = %d\n", x)
int main(void) {
int apple = 10;
PRINT(apple);
}- A. apple = 10
- B. 10 = 10
- C. x = 10
- D. Compilation error
Correct answer: A. apple = 10
The # operator stringizes the macro argument as written in source, turning the identifier apple into the string literal "apple", so the call expands to printf("apple" " = %d\n", apple), printing "apple = 10".
More C Programming questions
- What is printed? c #define CONCAT(a, b) a ## b int xy = 100; printf("%d", CONCAT(x, y));
- What is printed? c #define N 5 #undef N #define N 10 printf("%d", N);
- 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));