C | C Quiz – 113 | Question 1

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





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
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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.