S
somenath
Hi All,
I was going through one of the exercise of one C tutorial .
In that they have given one small code and asked about the output.
#include <stdio.h>
int main(void)
{
int x = 0xFFFFFFF0;
signed char y;
y = x;
printf("%x\n", y);
return 0;
}
Output of the program is
fffffff0
The explanation they have given as bellow
Since %x is being used for printing, the printf statement will promote
y to an integer and hence fffffff0 will be printed.
I have doubt about the explanation.
My understanding is
1) if we assign a signed variable more than its max size it will
overflow so the behavior is undefined .
2) And in the explanation it says %x promote y to an integer but I
think it converts its argument to hexadecimal.
Is my understanding wrong?
Please help.
Regards,
Somenath
I was going through one of the exercise of one C tutorial .
In that they have given one small code and asked about the output.
#include <stdio.h>
int main(void)
{
int x = 0xFFFFFFF0;
signed char y;
y = x;
printf("%x\n", y);
return 0;
}
Output of the program is
fffffff0
The explanation they have given as bellow
Since %x is being used for printing, the printf statement will promote
y to an integer and hence fffffff0 will be printed.
I have doubt about the explanation.
My understanding is
1) if we assign a signed variable more than its max size it will
overflow so the behavior is undefined .
2) And in the explanation it says %x promote y to an integer but I
think it converts its argument to hexadecimal.
Is my understanding wrong?
Please help.
Regards,
Somenath