ProgrammingVery hardAccenture · C · Advanced
What is printed?
What is printed?
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main(void) {
int i = 3, j = 1;
int m = MAX(i++, j++);
printf("%d %d %d", m, i, j);
return 0;
}- A. 3 4 2
- B. 4 5 2
- C. 4 4 2
- D. 3 5 2
Correct answer: B. 4 5 2
The expansion evaluates i++ in the condition (3 > 1, sequence point) and again in the chosen branch, so m = 4, i = 5; j++ runs once, so j = 2.
More C Programming questions
- In C, sizeof(char) is:
- Which storage class makes a local variable keep its value between calls to the function?
- The end of a C string is marked by:
- Which declaration makes p a pointer to an int?
- A line such as #include <stdio.h> is processed by:
- Which printf format specifier is meant for printing a pointer value (an address)?