ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
#define CONCAT(a, b) a ## b
int xy = 100;
printf("%d", CONCAT(x, y));- A. 100
- B. Compilation error: a and b are not valid identifiers to paste
- C. 0
- D. xy
Correct answer: A. 100
The ## operator pastes its operands together at the token level before macro expansion completes, so CONCAT(x, y) becomes the single identifier xy, referring to the existing variable xy = 100.
More C Programming questions
- 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));
- What is printed? c #define EMPTY #define SEMI ; int x = 5 EMPTY SEMI printf("%d", x);