Well, char and unsigned char variables get promoted to int type under certain circumstances (like when used as argument to a function, or when assigned to an int variable, or when used in mathematical expressions mixed in with int thingies).
When getting promoted to int, the difference is that unsigned char has the upper bits padded with zeros, whereas char has the upper bits padded with the value of the most significant bit. There is a very good reason for this (if you intend to use them as numbers.)
Try this, and make sure you understand what's happening:
Code:
#include<iostream>
int main()
{
char char_variable;
unsigned unsigned_char_variable;
int int1;
int int2;
int whole_number;
whole_number = 143;
char_variable = whole_number;
unsigned_char_variable = whole_number;
int1 = char_variable;
int2 = unsigned_char_variable;
std::cout << "whole_number = " << whole_number
<< std:: endl;
std::cout << " Check it out:"
<< std::endl;
std::cout << " int1 = " << int1
<< ", int2 = " << int2
<< std::endl
<< std::endl;
std::cout << " Hey, what happened here? Well, show the values in hex:"
<< std::endl;
std::cout << std::hex;
std::cout << " whole_number = " << whole_number << "(hex)"
<< std::endl;
std::cout << " int1 = " << int1 << "(hex)"
<< ", int2 = " << int2 << "(hex)"
<< std::endl;
return 0;
}
Dave