asd*_*gry 1 c++ variables declaration
在赋值之前,我应该在 C++ 程序的顶部声明变量吗:
int i;
std::string x;
std::string retval;
x = "foo";
i = 5;
retval = somefunction();
Run Code Online (Sandbox Code Playgroud)
或者,通过以下方式为变量赋值是否正确/可接受:
int i = 5;
std::string x = "foo";
std::string retval = somefunction();
Run Code Online (Sandbox Code Playgroud)
我是 C++ 的新手,我想知道 C++ 社区接受哪种方式。