ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
#define CONCAT(a, b) a##b
int main(void) {
int xy = 100;
printf("%d", CONCAT(x, y));
}- A. xy
- B. 0
- C. 100
- D. Compilation error: a##b is invalid syntax
Correct answer: C. 100
The ## operator pastes tokens together at preprocessing time: CONCAT(x, y) becomes the single identifier `xy`, which the compiler then sees as a reference to the variable xy = 100.
More C Programming questions
- What is printed? c #if defined(FEATUREX) && !defined(FEATUREY) #define MODE 1 #elif !defined(FEATUREX) #define MODE 2 #else #define MODE 3…
- What is printed? c #define INCREMENT(x) x = x + 1 int main(void) { int a = 5, b = 10; if (a > 0) INCREMENT(a); else INCREMENT(b)…
- What happens? c int getDangling(void) { int local = 42; return &local; } int main(void) { int p = getDangling(); printf("%d", p); }
- What happens? (Signed integer overflow.) c #include <limits.h> int main(void) { int x = INTMAX; int y = x + 1; printf("%d", y); }
- What happens? c int p = malloc(sizeof(int)); p = 10; free(p); printf("%d", p);
- What happens? c int divide(int a, int b) { return a / b; } int main(void) { printf("%d", divide(10, 0)); }