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 1 of 4.
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.
Mohd pv vanimal said:
7 years ago
include<stdio.h>
int main()
{
printf("%d\n", 'C'); //67
printf("%d\n", 'C' * -1); //-67
printf("%d\n", ~('C' * - 1)); //66
printf("%c\n",~('C' * -1)); //B
return 0;
}
In 2's complement, the value of ~(-67) is 66.
int main()
{
printf("%d\n", 'C'); //67
printf("%d\n", 'C' * -1); //-67
printf("%d\n", ~('C' * - 1)); //66
printf("%c\n",~('C' * -1)); //B
return 0;
}
In 2's complement, the value of ~(-67) is 66.
(2)
Digvijay said:
3 years ago
ASCII value of 67 is (01000011).
67*-1= -67.
In C negative values are treated with 2's complement so its 1's complement is 10111100 + 1.
Its 2's complement is 10111101.
Now apply ~ to its 2's complement.
Therefore it becomes- 01000010.
It's the ASCII value of B(66).
67*-1= -67.
In C negative values are treated with 2's complement so its 1's complement is 10111100 + 1.
Its 2's complement is 10111101.
Now apply ~ to its 2's complement.
Therefore it becomes- 01000010.
It's the ASCII value of B(66).
(7)
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).
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.
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 ~.
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
First find binary value for 67
67=01000011
take 1's complement:
that is make 0's complement and add 1
10111100+1=10111101
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'
~ indicate one's complement in c
~(-67)=66 so 66 ASCII value of character 'B'
Hariraj said:
2 decades ago
ASCII Value of 'C' is 67.
67*-1=-67
applying bitwise not(~) to -67 will result in 66, which is the ASCII value of 'B'.
67*-1=-67
applying bitwise not(~) to -67 will result in 66, which is the ASCII value of 'B'.
Sindhu said:
1 decade ago
Is ~ of all negative numbers result in positive numbers whose value is one less than its negative value?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers