OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

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

Choose one option.
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:

  1. Variable initialization: b = 5
  2. Line a = max(4, 5): Function max() is declared but not defined; this line would normally cause a linker error.
  3. Line a = b + 0: This assignment overwrites a with the value of b + 0 = 5 + 0 = 5.
  4. printf("%d", a): Prints the current value of a, which is 5.
  5. Output: 5