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;
}
Discussion:
32 comments Page 2 of 4.
Venkat said:
1 decade ago
Here 01000010 = 66 can be like 2^1+2^6 = 2+64 = 66.
Anu said:
1 decade ago
How 01000010 is 66? Can someone explain please?
Prashanth said:
1 decade ago
Why to use 1's compliment? Any one please.
Chandan kumar said:
1 decade ago
Hope it will help you.
67*-1 = -67;
Binary representation of 67: 01000011.
-67 can be represented as 2's complement of 67.
So we will compute 2's complement of 67.
1's complement of 01000011 is 10111100.
After adding 1 in the result we get: 10111101. (2's complement of 67 i.e -67)
~ (10111101) = 01000010(66).
66 is ASCII value of B so on execution of the program B is printed.
67*-1 = -67;
Binary representation of 67: 01000011.
-67 can be represented as 2's complement of 67.
So we will compute 2's complement of 67.
1's complement of 01000011 is 10111100.
After adding 1 in the result we get: 10111101. (2's complement of 67 i.e -67)
~ (10111101) = 01000010(66).
66 is ASCII value of B so on execution of the program B is printed.
Prasad said:
1 decade ago
Hey just to avoid confusion.
(<number>*-1)= multiplying <number> by -1 = 2's compliment.
~(number)= 1's compliment.(just inverting the binary digit)
Hope this helps.
(<number>*-1)= multiplying <number> by -1 = 2's compliment.
~(number)= 1's compliment.(just inverting the binary digit)
Hope this helps.
Jitendra said:
1 decade ago
@Tarun is absolutly right.
Swati said:
1 decade ago
Vallabh is right.
Tarun said:
1 decade ago
~n=-(n+1)
'c'*(-1)=67*(-1)=-67
~(-67)=-(-67+1)=66
66='B'
'c'*(-1)=67*(-1)=-67
~(-67)=-(-67+1)=66
66='B'
(1)
Diya said:
1 decade ago
What does this * in 67*-1 mean?
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).
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).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers