I am new to C ++. The following is a sample code:
int main(int argc, char* argv[]) { char ch1; int int1; cin >> ch1; cin >> int1; cout << ch1 << '\n'; cout << int1 << '\n'; return 0; }
When I run the program and enter the following:
ag
I get the output:
a 32767
I understand "a", but why is the integer value 32767? I just want to check and see what happens if, instead of the numeric value assigned to int1, I used 'z'.
I am trying to enter:
Oh
... and I get the same results.
Now, if instead of int int1 I use short int1 and run the program with the input:
ag
I get the output:
a 0
PS
sizeof(int) = 4 sizeof(short) = 2
I am using a 64-bit machine.
source share