I was doing this simple program and my mind got stuck
#include<stdio.h>
int main()
{
signed int a;
signed char c;
unsigned char b;
b = 0xf4;
a = (signed)b; // 1)this assignment should be same
c = (signed)b;
printf("%d\n",a);
a = c; // 2)as this one
printf("%d \n",a);
return 0;
}
a = 244, a = -12
I tried to make sure that assignment is as smooth as it can be but I am getting two different answers and I expected both as -12. What small thing I am missing?
The relevant question was
{
b = 0xf4;
c = 0xf4;
a = (signed int)b; //trying to save sign but get 244
printf("%d\n", a);
a = c; //sign saved here and got -3
printf("%d", a);
}
244, -3
so i am trying to save the sign from an unsigned char. Is this possible in this manner?