2 c++ variables initialization
当我做的事情
#include<iostream>
int main()
{
int x;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到一个关于x是一个未引用的局部变量的警告(我假设因为我创建了一个变量,然后没有使用它),为什么这会给我一个警告呢?
lui*_*bal 21
可能是因为你没有浪费记忆.
此外,代码变得肮脏且难以理解,更不用说程序员通常不会定义他们不需要的变量,所以它就是"这真的是你的意思吗?" 警告.
Zif*_*fre 16
这可能是为了阻止这样的事情:
void some_func() {
int a, b, c, d, e;
...
do_something_with(a);
do_something_with(b);
do_something_with(c);
do_something_with(d);
do_something_with(c); // after hours of reading code, e looks like c: BUG!!
}
Run Code Online (Sandbox Code Playgroud)