Related Articles

# C | C Quiz – 113 | Question 1

• Difficulty Level : Medium
• Last Updated : 28 Jun, 2021

Output of following program under the assumption that numbers are stored in 2’s complement form.

 `#include``int` `main()``{``   ``printf``(``"%c\n"``, ~(``'C'` `* -1));``   ``return` `0;``}`

Contributed by Sowmya.L.R
(A) B
(B) A
(C) Compiler Error
(D) C

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

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up