Exams › GATE › Technical
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
- z K S
- 122 75 83
- * - +
- 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
- Consider the following representation of a number in IEEE 754 single-precision floating-point format with a bias of 127: S: 1 E: 10000001 F: 11100000000000000000000 Here S, E, and F denote the sign, exponent, and fraction components of the floating-point representation. The above representation, rounded to 2 decimal places, is
- Which one of the following statements is false?
- Consider two set-associative cache memory architectures: WBC, which uses the write-back policy, and WTC, which uses the write-through policy. Both use the LRU (Least Recently Used) block replacement policy. The cache memory is connected to main memory. Which of the following statements is/are TRUE?
- Suppose a program is running on a non-pipelined single-processor computer system. The computer is connected to an external device that can interrupt the processor asynchronously. The processor needs to execute the interrupt service routine (ISR) to serve this interrupt. The following steps, not necessarily in order, are taken by the processor when the interrupt arrives: (i) The processor saves the content of the program counter. (ii) The program counter is loaded with the start address of the ISR. (iii) The processor finishes the present instruction. Which ONE of the following is the correct sequence of steps?
- The number $-6$ can be represented as $1010$ in 4-bit 2’s complement representation. Which of the following is/are CORRECT 2’s complement representation(s) of $-6$?
- A partial datapath of a processor is given in the figure, where RA, RB, and RZ are 32-bit registers. Which option(s) is/are CORRECT related to arithmetic operations using the datapath as shown?
⚔️ Practice GATE Technical free + battle 1v1 →