C Programming · Question 7 · Medium

What will be the output of the following C program?

#include <stdio.h>

int main(void) {
    int x = 12, y = 10;
    printf("%d %d %d", x & y, x | y, x ^ y);
    return 0;
}
  1. 8 14 2
  2. 8 14 6
  3. 12 10 6
  4. 0 22 22
Answer and explanation

Answer: B. 8 14 6

Explanation: 12 is 1100 and 10 is 1010 in binary. AND gives 1000 (8), OR gives 1110 (14), and XOR gives 0110 (6).

Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?

Practise c programming

Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.

More c programming questions

More technical & programming practice

Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge