Variable Scope in C++?

前端 未结 4 1344
半阙折子戏
半阙折子戏 2021-01-27 14:52

In c++, any variables declared in main will be available throughout main right? I mean if the variables were declared in a try loop, will they would still be accessible througho

4条回答
  •  清酒与你
    2021-01-27 15:15

    That's normal; each { ... } block mark a new scope, and variables declared inside it are local to it. If you want number to be available throughout all main declare it outside the try block.

提交回复
热议问题