ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#define SQUARE(x) x * x
int main(void) {
int a = 5;
printf("%d", SQUARE(a + 1));
}- A. 36
- B. 11
- C. a + 1 * a + 1
- D. Compile-time error: SQUARE needs parentheses around x
Correct answer: B. 11
Macros do pure textual substitution with no operator-precedence awareness: SQUARE(a + 1) expands to a + 1 * a + 1, which by normal precedence is a + (1*a) + 1 = 5 + 5 + 1 = 11, not (a+1)*(a+1)=36 as intended.
More C Programming questions
- What is printed? c #define TWICE(x) x + x printf("%d", 2 TWICE(3));
- What is printed? c #define LOG(msg) printf("[LOG] %sn", msg) #ifdef DEBUG #define TRACE(msg) LOG(msg) #else #define TRACE(msg) #endif int…
- What is printed? c #define CONCAT(a, b) a##b int xy = 42; printf("%d", CONCAT(x, y));
- What is printed? c #if defined(STDC) && STDCVERSION >= 199901L int x = 10; #else int x = 20; #endif printf("%d", x);
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define CLAMP(x, lo, hi) MIN(MAX(x, lo), hi) #define MAX(a, b) ((a) > (b) ?…
- What is printed? c #define INCR(x) (++x) int arr[3] = {10, 20, 30}; int i = 0; printf("%d", arr[INCR(i)]);