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

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 main()
{
    int a = 4;
    if ( a ^ a && (a ^ a) || a)
        printf("%d", a);
    return 0;
}
Choose one option.
Show answer & explanation
Answer: D. 4

The condition evaluates as follows: a ^ a (XOR of a with itself) = 0, then 0 && (a ^ a) = 0, then 0 || a = 4 (truthy). Since the if condition is true, printf prints the value of a, which is 4.

Step-by-step Derivation:
Step-by-step evaluation:

  1. a = 4 (binary: 100)
  2. Evaluate condition: a ^ a && (a ^ a) || a
  3. a ^ a = 4 ^ 4 = 0 (XOR cancels identical bits)
  4. 0 && (a ^ a) = 0 && 0 = 0 (AND with 0 is always 0)
  5. 0 || a = 0 || 4 = 4 (OR with non-zero gives non-zero)
  6. if (4) → condition is TRUE (non-zero value)
  7. printf("%d", a) executes and prints: 4