Why do I get an “Unreferenced Local Variable” warning? (C++)


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?


Answers:


Probably because you're wasting memory for nothing.

Besides, the code becomes dirty and harder to understand, not to mention that programmers don't usually define variables they don't need, so it's sort of a "is this really what you meant?" warning.