QUESTION 32 What will be the output of the program given below?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
QUESTION 32
What will be the output of the program given below?
#include <stdio.h>
int main()
{
int a, b = 5;
int max(int, int);
a = max(4, 5);
a = b + 0;
printf("%d", a);
return 0;
}
**MCQ
Show answer & explanation
Answer: C. 5
The program declares b = 5 and later assigns a = b + 0, which equals 5. Although a = max(4, 5) is called, this function is never defined—only declared as a function prototype. In C, the printf("%d", a) outputs the value of a after the last assignment, which is 5. The undefined max() function call would cause a linker error in strict compilation, but many online judges or lenient compilers may execute this and print 5 from the final assignment.
Step-by-step Derivation:
- Variable initialization:
b = 5 - Line
a = max(4, 5): Functionmax()is declared but not defined; this line would normally cause a linker error. - Line
a = b + 0: This assignment overwritesawith the value ofb + 0 = 5 + 0 = 5. printf("%d", a): Prints the current value ofa, which is5.- Output:
5