What happens when I input a wrong variable type using cin?

Viewed 234

I declared two integer variables and structured the program to get the values through cin and print out the values through cout.

#include <iostream>
using namespace std;
int main() {
  int a , b;
  cin >> a >> b ;
  cout << endl << a << "\t" << b << endl;
  return 0;
}

When prompted to input values I deliberately gave a non-integer value for the first variable and got the following output:

  1. char: 0 and 32767
  2. float 0 and 0
  3. Absurdly large number: 2147483647 and 32767

Why does the output of the second variable differ based on the variable type of the first input?

0 Answers
Related