ProgrammingVery hardTCS NQT · Infosys
#define ADD(a,b) a+b. What does printf("%d", 2 * ADD(1,2) * 3) print?
- A. 8
- B. 9
- C. 18
- D. 12
Correct answer: A. 8
The expansion is 2 * 1+2 * 3, which is 2 + 6 = 8. Macro arguments and bodies need parentheses to behave like a function call.
More C Programming questions
- #define HALF(x) x / 2. With int a = 5, b = 3, what does printf("%d", HALF(a + b)) print?
- char s[] = "2024"; int sum = 0; for (int i = 0; s[i] != '0'; i++) sum += s[i] - '0'; What is sum?
- int count = 0; for (int i = 1; i <= 10; i++) for (int j = i; j <= 10; j += i) count++; What is count at the end?
- A contest program must test whether n is prime for n up to 10^9 with a 1 second limit. Which method is fast enough for one query?
- How many elements in the 1 to 50 range have exactly three 1 bits in binary?
- char buf[5] = "abcd"; printf("%zu", sizeof(buf) - strlen(buf)); What is printed?