Reading a number when no input given in C++

81 Views Asked by At

Is the following code prone to undefined behavior when end of file or an empty line is provided as input?

  unsigned long long i;
  cin >> i;

From what I've observed using Compiler Explorer, it seems i gets some random value, likely one that happened to be at that memory location. But it's often the case that when compilers behave this way, the standard in fact specifies UB.

0

There are 0 best solutions below