ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
#define DEBUG_PRINT(fmt, ...) printf(fmt, __VA_ARGS__)
int main(void) {
DEBUG_PRINT("%d and %d\n", 1, 2);
}- A. %d and %d
- B. 1 and 2
- C. Compile-time error: variadic macros are not standard C
- D. fmt and __VA_ARGS__
Correct answer: B. 1 and 2
__VA_ARGS__ is a standard C99 feature for variadic macros: the ... parameter collects any extra arguments beyond fmt, and __VA_ARGS__ substitutes them (here, 1, 2) in place. The macro expands to printf("%d and %d\n", 1, 2), printing 1 and 2.
More C Programming questions
- What is printed? c #define SAFEDIV(a, b) ((b) != 0 ? (a) / (b) : 0) int main(void) { int x = 10, y = 0; printf("%d", SAFEDIV(x, y)); }
- What is printed? c #if 1 #define VALUE 100 #elif 0 #define VALUE 200 #else #define VALUE 300 #endif printf("%d", VALUE);
- What is printed? c #define ISPOSITIVE(x) ((x) > 0) #define ISNEGATIVE(x) ((x) < 0) #define ISZERO(x) ((x) == 0) int classify(int n) { if…
- Assume a 64-bit LP64 ABI. What is printed? c int findMax(int arr, int n) { int maxPtr = arr; for (int i = 1; i < n; i++) if (arr[i] >…
- Assume a 64-bit LP64 ABI. What is printed? c int binarySearch(int arr, int n, int target) { int lo = 0, hi = n - 1; while (lo <= hi) { int…
- Assume a 64-bit LP64 ABI. What is printed? c int sumArray(int arr, int n) { if (n == 0) return 0; return arr + sumArray(arr + 1, n - 1); }…