ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#define PRINT(x) printf(#x " = %d\n", x)
int main(void) {
int count = 5;
PRINT(count);
}- A. 5 = %d
- B. count = 5
- C. x = 5
- D. Compile-time error: #x inside a string is invalid
Correct answer: B. count = 5
# is the stringizing operator: #x converts the literal token count (whatever was textually passed as the argument) into the string literal "count", before any further substitution. The macro expands to printf("count" " = %d\n", count), and adjacent string literals "count" and " = %d\n" concatenate at compile time, printing count = 5.
More C Programming questions
- What is printed? c #define MULTILINE(x) do { x = x 2; x = x + 1; } while (0) int main(void) { int v = 5; MULTILINE(v); printf("%d", v); }
- What is printed? c #define DEBUGPRINT(fmt, ...) printf(fmt, VAARGS) int main(void) { DEBUGPRINT("%d and %dn", 1, 2); }
- 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] >…