edited by
1,086 views
1 votes
1 votes
<code>#include <stdio.h>
        int main()
        {
            unsigned int b = 20;
            b = ~b;
            printf("%d\n", b);
        }</code>
edited by

1 Answer

Best answer
6 votes
6 votes
unsigned int b=0000000000010100 (assuming int = 2 bytes)

b=~b, therefore b=1111111111101011

now %d specifier does not know anything about signed or unsigned, it just assume that the given number is in signed 2's complement form..

and hence value returned will be -21...
selected by

Related questions

2 votes
2 votes
1 answer
1
2 votes
2 votes
2 answers
2
Khushal Kumar asked Jul 8, 2017
1,286 views
#include<stdio.h int main(void){ int a = 1, 2, 3; printf("%d", a); return 0;}
3 votes
3 votes
2 answers
3
Aghori asked Jul 14, 2017
1,189 views
#include <stdio.h int main() { int *p = (int *)20; int *q = (int *)30; printf("%d", q - p); }Explain which one of the following is correct?Compilation error.102None of th...