I was just playing with characters using a very simple C++ program, let me explain the situation -:
#include<iostream>
int main(){
char c;
std :: cin >> c;
std :: cout << "The integer value of character entered is : " << int(c) << '\n';
int m = 12 + 'á';
std :: cout << m << '\n';
return 0;
}
now when I execute the above program I enter the value of c as 'á' which is in the spanish character set and is typed as "Alt + 160" in windows and because my computer implements the plain old char as a signed char the above program outputs the integer value of 'á' as -96, but a strange thing happens when I output the value of m it returns the output as -19 instead of -84, while if I execute the following program -:
#include<iostream>
int main(){
signed char c;
std :: cin >> c;
std :: cout << "The integer value of character entered is : " << int(c) << '\n';
int m = 12 + c;
std :: cout << m << "\n";
return 0;
}
I get the correct output value, now I am confused as to why is this happening, if every character is backed by some number in the computer then why is not the expression m = 12 + 'á' evaluated as m = 12 + (-96). Kindly enlighten me regarding this issue. I am using Windows 7 and Dev C++