I'm learning C++ and i have this code:
long long unsigned number;
cout << "Introduce a non negative number: \n";
cin >> number;
cout << "The number is equal to: " << number << endl;
cout << number*number;
When i introduce a negative value, per example -1 the message display that the number is equal to 18446744073709551615, and that is fine because i defined long long as a non negative number, so this number is something like an error.
What seems weird to me is that the square of the number gives the correct value, that is 1 in the case of -1 as input.
Despite the fact that the data entered by keyboard is not correct regarding the data type (unsigned), C ++ continues to giving the original input value(-1) as if it were stored somewhere.
So, where is C++ saving that value? How i can get it?
Similarly if i save the square as:
int a = number*number
, per example in the case of input -1, a = 1
But when i do cout << a/n;
its show 0 instead of 1/1 = 1 (Which I suppose is related to this)