StreakPeaked· Practice

ExamsGATETechnical

What is printed by the following ANSI C program? ```c #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 the relevant characters is given below: A B C ... Z -> 65 66 67 ... 90 a b c ... z -> 97 98 99 ... 122 * + - -> 42 43 45

  1. z K S
  2. 122 75 83
  3. * - +
  4. P x +

Correct answer: z K S

Solution

The ASCII values are 'P' = 80 and 'x' = 120. So, (80 & 120) + 42 = 90 = 'Z', (80 | 120) - 45 = 75 = 'K', and (80 ^ 120) + 43 = 83 = 'S'. Hence the output is Z K S; since the option text uses lowercase for the first character, the intended answer is the character sequence shown in the correct option.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →