ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#if 1
#define VALUE 100
#elif 0
#define VALUE 200
#else
#define VALUE 300
#endif
printf("%d", VALUE);- A. 100
- B. 200
- C. 300
- D. Compile-time error: multiple #define VALUE in conditional branches conflict
Correct answer: A. 100
Only ONE branch of an #if/#elif/#else chain is actually compiled (the preprocessor discards the others entirely, including their #define directives). Since #if 1 is always true, only #define VALUE 100 is ever seen, so VALUE expands to 100 with no conflict.
More C Programming questions
- 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); }…
- Assume a 64-bit LP64 ABI. What is printed? c int compareInts(const void a, const void b) { int ia = (const int )a; int ib = (const int )b…
- Assume a 64-bit LP64 ABI. What is printed? c int fibIterative(int n) { int a = 0, b = 1; for (int i = 0; i < n; i++) { int tmp = a + b; a…