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.
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'.
Nik said:
1 decade ago
How come bitwise not (~) to -67 is 66 , why not 67 itself?
Satya said:
1 decade ago
@Nik because c language follows the one's complement signed number representation
Mah said:
1 decade ago
Thank you hariraj.
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'
Nita said:
1 decade ago
Hariraj is right.
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
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 ~.
Sindhu said:
1 decade ago
Is ~ of all negative numbers result in positive numbers whose value is one less than its negative value?
Rhana said:
1 decade ago
Hariraj is right.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers