C++ – get an “Unreferenced Local Variable” warning? (C++)

cinitializationvariables

When I do something like

#include<iostream>
int main()
{
    int x;
    return 0;
}

I get a warning about x being an unreferenced local variable (I assume becuase I created a variable, then did not use it), why does this give me a warning though?

Best Answer

Because usually people don't create unreferenced variables intentionally. So if there is an unreferenced variable in a program, usually it is a sign that you have a bug somewhere, and the compiler warns you about it.