Skip to content
GATEiit

GATE CSE 2022 Q44: Bitwise operations on characters P and x in C

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

Select one 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

WhatsAppDownload image

Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key