C | C Quiz – 113 | Question 1
Output of following program under the assumption that numbers are stored in 2’s complement form.
#include<stdio.h> int main() { printf ( "%c\n" , ~( 'C' * -1)); return 0; } |
Contributed by Sowmya.L.R
(A) B
(B) A
(C) Compiler Error
(D) C
Answer: (A)
Explanation: executed without any error or warning messages and the output for the above code is
‘B’
The above program processes as below
Step 1:
First (‘C’ *-1) is processed
ASCII value of ‘C’ is 67 and it is multiplied with -1 as
67 * (-1) = -67
Step 2:
The binary representation of -67 is 10111101
The bitwise negation of 10111101 becomes (01000010 ) 2 = (66) 10
Step 3:
66 is the ASCII value of ‘B’
So ~(‘C’*-1) = 66 and so the output of the above the program is B
Quiz of this Question
Please Login to comment...