GateAI
Programming in C

GATE CSE 2022 · Q44

MCQ2 marksMedium

Time

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 ", c, d, e); return 0; }ASCII encoding for relevant characters is given below

GATE CSE 2022 Q44 diagram 1
GATE CSE 2022 Q44 diagram 2
GATE CSE 2022 Q44 diagram 3

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) z K S

Programming in C

First, find the ASCII integer values of 'P' and 'x':

  • 'P' is the 16th16^{\text{th}} uppercase letter: ASCII(′P′)=65+15=80=010100002\text{ASCII}('P^{\prime}) = 65 + 15 = 80 = 01010000_2

  • 'x' is the 24th24^{\text{th}} lowercase letter: ASCII(′x′)=97+23=120=011110002\text{ASCII}('x^{\prime}) = 97 + 23 = 120 = 01111000_2

Now, perform the bitwise operations and arithmetic:

  1. Bitwise AND (&):

    a & b=010100002 & 011110002=010100002=80a \ \&\ b = 01010000_2 \ \&\ 01111000_2 = 01010000_2 = 80
    c=(a & b)+′∗′=80+42=122c = (a \ \&\ b) + '*' = 80 + 42 = 122

    The character with ASCII value 122122 is 'z' (97+25=12297 + 25 = 122).

  2. Bitwise OR (|):

    a∣b=010100002∣011110002=011110002=120a \mid b = 01010000_2 \mid 01111000_2 = 01111000_2 = 120
    d=(a∣b)−′−′=120−45=75d = (a \mid b) - '-' = 120 - 45 = 75

    The character with ASCII value 7575 is 'K' (65+10=7565 + 10 = 75).

  3. Bitwise XOR (^):

    a⊕b=010100002⊕011110002=001010002=32+8=40a \oplus b = 01010000_2 \oplus 01111000_2 = 00101000_2 = 32 + 8 = 40
    e=(a⊕b)+′+′=40+43=83e = (a \oplus b) + '+' = 40 + 43 = 83

    The character with ASCII value 8383 is 'S' (65+18=8365 + 18 = 83).

Since printf uses the %c specifier, it outputs the characters 'z', 'K', and 'S' separated by spaces: z K S.

Hence, (A) is the correct option.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q44 of the GATE CSE 2022 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 19 of them are 2-mark MCQs like this one, and GATE CSE 2022 has 3.

How GATE tests Programming in C

More from GATE CSE 2022

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2022 · Q44 · MCQ

What is printed by the following ANSI C program? #include 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 ", c, d, e); return 0; } ASCII encoding for relevant characters is given below

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.