ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#define SQUARE(x) x * x
int main(void) {
int a = 3;
printf("%d", SQUARE(a + 1));
}- A. 7
- B. 16
- C. 9
- D. 4
Correct answer: A. 7
Macros are pure text substitution with no implicit parentheses: SQUARE(a+1) expands to a + 1 * a + 1 = 3 + 1*3 + 1 = 3+3+1 = 7 (multiplication binds tighter than the surrounding addition).
More C Programming questions
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int apple = 10; PRINT(apple); }
- 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));