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 a = 40;

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

The global variable a = 40 is shadowed by the local variable a declared in main(). The local a is uninitialized when declared, but then immediately assigned b + 0 where b = 5, so a = 5. The printf outputs the local a, which is 5, not the global value of 40.

Step-by-step Derivation:

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