1

When cleaning up some code that I have found online, I came across with this weird c++ line:

if (int i = 1) std::cout << i;

With LLVM it compiled fine and the console output is 1, but how does the scope is handled in here, shouldn't the i variable be only accessible inside the conditional (inside the parenthesis)? And how is that possible to be evaluated to true, isn't an assignment a void operation and with no value, so 0/false? What is going on with this line?

Rui Pedro
  • 95
  • 1
  • 8

0 Answers0