T
tinesan
Hello fellow C programmers,
I'm just learning to program with C, and I'm wondering what the
difference between signed and unsigned char is. To me there seems to
be no difference, and the standard doesn't even care what a normal char
is (because signed and unsigned have equal behavior).
For example if someone does this:
unsigned char a = -2; /* or = 254 */
signed char b = -2; /* or = 254 */
putchar(a);
putchar(b); /* both print the same character (ex ascii 254)*/
-------------
It seems to me that it doesn't matter whether char is signed or
unsigned, because the output functions just look at the bit pattern and
deal with it as a positive number.
Also, I assigned a negative number to unsigned char, it wraps around
and creates the same bit pattern as assigning the same negative number
to signed char.
So my question is, what really is the difference between unsigned and
signed char?
Also, for other integral types, are the normal types always equal to
the signed types (int = signed int, long = signed long,etc. etc.)... or
is that implementation defined just like for chars?
Any help will be appreciated.
I'm just learning to program with C, and I'm wondering what the
difference between signed and unsigned char is. To me there seems to
be no difference, and the standard doesn't even care what a normal char
is (because signed and unsigned have equal behavior).
For example if someone does this:
unsigned char a = -2; /* or = 254 */
signed char b = -2; /* or = 254 */
putchar(a);
putchar(b); /* both print the same character (ex ascii 254)*/
-------------
It seems to me that it doesn't matter whether char is signed or
unsigned, because the output functions just look at the bit pattern and
deal with it as a positive number.
Also, I assigned a negative number to unsigned char, it wraps around
and creates the same bit pattern as assigning the same negative number
to signed char.
So my question is, what really is the difference between unsigned and
signed char?
Also, for other integral types, are the normal types always equal to
the signed types (int = signed int, long = signed long,etc. etc.)... or
is that implementation defined just like for chars?
Any help will be appreciated.