GATE CSE 2022 Q44: Bitwise operations on characters P and x in C
- Programming and Data Structures
- 2 marks
- MCQ
- −2/3 if wrong
Question
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[]){
char a = 'P';
char b = 'x';
char c = (a & b) + '*';
char d = (a | b) - '-';
char e = (a ^ b) + '+';
printf("%c %c %c\n", c, d, e);
return 0;
}ASCII encoding for relevant characters is given below
A = 65, B = 66, C = 67, …, Z = 90
a = 97, b = 98, c = 99, …, z = 122
* = 42, + = 43, − = 45
Try it: multiple choice: exactly one correct option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation
Answer: A (official GATE 2022 final answer key)
Concept used: Bitwise AND/OR/XOR on ASCII codes, then printing with %c shows characters, not numbers.
First step: 'P' = 80 = 01010000 and 'x' = 120 = 01111000; compute AND, OR and XOR in binary.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key
More Programming and Data Structures PYQs
- 2026 Session 1 · Q23Non-leaf indices in a 1-indexed binary heap with n odd
- 2026 Session 1 · Q24Empty slots after linear-probing inserts with h(x) = (x+7) mod 11
- 2026 Session 1 · Q33Maximum height of a full binary tree with 23 nodes
- 2026 Session 1 · Q34Output of a C function with a shadowed block variable
- 2026 Session 1 · Q39Recursive length of a non-empty singly linked list
- 2026 Session 1 · Q40Third insertion that can never yield a complete BST of 1..15