Signed and unsigned char both are used to store a single character. The characters are stored as per their ASCII values. For example, ‘A’ will be stored as 65 as it has value ‘65’ in the ASCII table.
You don’t need to specify keyword ‘signed’ for using signed char but you need to mention keyword ‘unsigned’ for using unsigned char. i.e.
Instead of writing
signed char name = ‘a’;
We can simply write it as:
char name = ‘a’;
But in the case of unsigned char, you need to use ‘unsigned’ keyword.
usigned char name = ‘a’;
However, this may not hold true for some machines. So, it is always a good practice to write signed or unsigned to avoid the confusion.
> The size of both signed and unsigned char is 1 byte or 8 bits.
> ASCII table has 128 characters ranging with values from 0 to 127. The remaining 127 characters is known as extended ASCII character set.
> In signed char, the extended set takes value from -128 to -1 whereas in unsigned char it takes value from 128 to 255.
Thus the range of signed char is -128 to 127 whereas that of unsigned char is 0 to 255.
If you try to give value 128 to signed char, it will take the value corresponding to the other side of the range i.e. -128. For signed char, the value next to 127 is -128 like in clock after 12 comes 1 and so on. 😀
Similar if you try to give value 256 to unsigned char, it will take value 0.
Just use them according to your requirements. Happy Coding 🙂 .
Further queries are welcomed.