737 views
1 votes
1 votes
int main()
{
unsigned int x = 1;
printf("Signed Result %d \n", ~x);
printf("Unsigned Result %ud \n", ~x);
return 0;

}

some one give detailed answer ...

(mainly how it works )

1 Answer

Best answer
2 votes
2 votes

Output:-

Signed Result = -2

Unsigned Result = (4294967294)10

Explanation:-

Now, x = 1 in decimal 

and in binary 0000 0000 0000 0000 0000 0000 0000 0001

operator ~ is complement of given number.

1's complement of x = 1 --->>> 1111 1111 1111 1111 1111 1111 1111 1110

and its unsigned value is = 4294967294

For signed value use 2's complement notation. Computers uses 2's complement to represent negative numbers.

1111 1111 1111 1111 1111 1111 1111 1110  Representing in 2's complement notation gives -2.

selected by

Related questions

0 votes
0 votes
2 answers
1
Hira Thakur asked Jun 22, 2017
948 views
anyone explain this prog?? how to output is evaluvated??int main(){ int x = 10, y; y = (x++, printf("x = %d\n", x), ++x, printf("x = %d\n", x), x++); printf("y ...
1 votes
1 votes
2 answers
2
ShiveshRoy asked Mar 25, 2016
2,423 views
Is set difference operator (-) used in relational algebra associative?