From the online cpp reference on Uninitialized variables:
It is possible to create a variable without a value. This is very dangerous, but it can give an efficiency boost in certain situations.
To create a variable without an initial value, simply don’t include an initial value:
// This creates an uninitialized int
int i;
The value in an uninitialized variable can be anything – it is unpredictable, and may be different every time the program is run. Reading the value of an uninitialized variable is undefined behaviour – which is always a bad idea. It has to be initialized with a value before you can use it.
#include <iostream>
int main()
{
int i; // uninitialized variable
// WARNING: This causes undefined behaviour!
std::cout << i << '\n';
i = 23; // initializing the variable
// Now it is safe to use.
std::cout << i << '\n';
return 0;
}
The value printed on the first line in the example above can be anything.
int a = 0, b = 0;acauses reading to cease, and leaves the character'a'waiting to be read on subsequent operations. This leaves the variable being read (and subsequent variables being read) unchanged. In your code, bothaandbare uninitialised, so accessing their values gives undefined behaviour. Since the input operations have failed, the output statement therefore give undefined behaviour i.e. anything can happen.