C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - Find Output of Program (Q.No. 6)
6.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("%c\n", ~('C'*-1));
    return 0;
}
A
B
C
D
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
32 comments Page 3 of 4.

Vallabh said:   1 decade ago
ASCII value of 'C'=67 (01000011)
67*-1=-67
in C negative values are treated with 2's compliment
so its 1's compliment is 10111100
and its 2's compliment is 10111101

Now apply ~ to its 2's compliment and it becomes 01000010 that is nothing but the ASCII value of B(66).

Anil said:   1 decade ago
Hariraj is right.

Balaji said:   1 decade ago
-67 is stored in 2's complement form in computer.

Rhana said:   1 decade ago
Hariraj is right.

Sindhu said:   1 decade ago
Is ~ of all negative numbers result in positive numbers whose value is one less than its negative value?

Vivek said:   1 decade ago
For using ~
first we will add 1 to the number and then we will change the sign.
for ex:
-67
-67+1=-66
and now we will change the sign that is equal to 66
how we use this sign ~.

Dhan said:   1 decade ago
For -67 we can calculate the binary value by:

First find binary value for 67
67=01000011
take 1's complement:
that is make 0's complement and add 1
10111100+1=10111101

Nita said:   1 decade ago
Hariraj is right.

Chaudhary paresh said:   1 decade ago
('C'*-1)--> ASCII Value of C equal to 67 so statement become(67*-1)=-67
~ indicate one's complement in c
~(-67)=66 so 66 ASCII value of character 'B'

Mah said:   1 decade ago
Thank you hariraj.


Post your comments here:

Your comments will be displayed after verification.