GATE 2022 CS – Question 44
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: A–Z = 65–90, a–z = 97–122, '*' = 42, '+' = 43, '−' = 45.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) z K S
Explanation
'P'=80 (01010000) and 'x'=120 (01111000). a&b=80, so c=80+42=122='z'. a|b=120, so d=120−45=75='K'. a^b=40, so e=40+43=83='S'. The output is `z K S`.