OA. free
Free
Qualcomm Embedded Systems & Hardware Core Computer Science Medium

QUESTION 37 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.

What will be the output of the program given below?

#include <stdio.h>

int a = 40;

int main()
{
    int a, b = 5;
    a = b + 0;
    printf("%d", a);
    return 0;
}
Choose one option.
Show answer & explanation
Answer: D. 5

The local variable a declared inside main() shadows the global variable a = 40. The local a is initialized with garbage (uninitialized), but b is explicitly initialized to 5. The assignment a = b + 0 sets local a to 5. The printf outputs the local a, which is 5, not the global value.

Step-by-step Derivation:

  1. Global scope: int a = 40; declares and initializes a global variable.
  2. In main(): int a, b = 5; declares two local variables. Local a is uninitialized (has garbage value initially), b = 5.
  3. Local variable a shadows the global a within main().
  4. a = b + 0; assigns 5 + 0 = 5 to local a.
  5. printf("%d", a); prints the local a, which is 5.
  6. Output: 5