data type

can anyone tell the significance of signed and unsigned char data types.... and their range of inputs....???
for e.g
1
2
3
4
signed char c1=-127;
unsigned char c2=-127;
printf("%c %c",c1,c2);
;

shouldnt c1 and c2 print different characters..........????
ie for c2 it should print sumthin invlaid as it is out of its range(on a 16 bit machine )also how do we determine data range on say 64 bit machine?????plz help
-127 is stored as 0x81 in memory. the only difference in terms of data type is how this memory is interpreted. As far as one byte characters go, -127 and 129 are the same.

I'm not as much help for a 64bit character, though this is why there are wide-characters and such.
one final question .... can we say that there is no difference between signed and unsigned character data type...... as the above code works fine?????
I don't think I'm exactly right about everything I posted. I do know that:
1
2
3
4
5
6
7
char a, b;
unsigned char c, d;

a = c = -127;
b = d = 129;

cout << a << " " << b << " " << c << " " << d;


will print the same thing for each variable.

A simple answer, there must be a difference if they exist, sorry I'm not help in that area.
> can we say that there is no difference between signed and unsigned character data type

No, we can't (or rather no, we shouldn't). Try this:

1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
    signed char c = -1 ;
    unsigned char u = -1 ;
    int i = c ;
    int j = u ;
    std::cout << i << ' ' << j << '\n' ;
}
Topic archived. No new replies allowed.