In the following code segment what will be:
- the result of function
- value of x
- value of y
{
unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
a. same, MAXINT, -1 b. not same, MAXINT, -MAXINT c. same , MAXUINT, -1 d. same, MAXUINT, MAXUINT e. not same, MAXINT, MAXUINT
Can someone explain me how its works or can just explain the snippet??
I know it’s about two’s complement n etc..
What is the significance of MAXINT and -1 ?
It is because of unsigned int and int thing – am I right ?
If you run this program, you will see that the answer a is wrong and c is the correct answer: