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.
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)
Noureen said:
7 years ago
Very well explained, Thanks @Mohd Pv Vanimal.
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)
Mayank said:
8 years ago
Very nice explanation @Vallabh.
Pallavi said:
8 years ago
Agree @Venkat.
Aminul said:
8 years ago
Yes, Right @Venkat.
Jayant said:
8 years ago
You are right @Vallabh.
Rahul said:
9 years ago
Thank you all for such a wonderful help. It is very helpful.
Alok said:
9 years ago
@Vallabh is correct.
Sowmiya said:
9 years ago
How ~67 comes to 66? Can someone explain please.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers