GATE / CS ARCHIVE

GATE CSE 2022 / QUESTION 44

GATE CSE 2022 Q44

Programming in C · Expressions, Operators & Types · Full GATE CSE 2022 paper

GATE 2022, Q44 2 marks · MCQ
Report issue

Expressions, Operators & Types

Question 44, GATE 2022: ANSI C uses char a='P',b='x'; char c=(a&b)+'*',d=(a|b)-'-',e=(a^b)+'+'; printf("%c %c %c\n",c,d,e). ASCII values P=80,x=120,*=42,−=45,+=43,z=122,K=75,S=83. Choose output: A z K S; B 122 75 83; C * − +; D P x +.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Using the provided ASCII values, a=P=80 and b=x=120. a&b=80, so adding *=42 gives 122, character z. a|b=120, so subtracting -=45 gives 75, character K. ab=40, so adding +=43 gives 83, character S. Thus the output is z K S, option A.

Binary P=01010000 and x=01111000. AND keeps their shared 1 bits (01010000); OR combines them (01111000); XOR keeps differing bits (00101000). The arithmetic uses integer promotions, and the resulting 122,75,83 fit char. %c converts the codes to characters; %d would have printed numbers instead.

Original paper, page 29 · Answer key