Consider the following code:
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int count123;
for (int c = 0; c < 10; c++)
{
count123 += c;
}
return 0;
}
Upon compilation I get the warning: warning C4700: uninitialized local variable 'count123' used
I know the reason is declaring count123 but not initializing it.
But if I declare count123 as a global variable as in the code below, the warning disappears.
#include "stdafx.h"
using namespace std;
int count123;
int _tmain(int argc, _TCHAR* argv[])
{
for (int c = 0; c < 10; c++)
{
count123 += c;
}
return 0;
}
As far as I know declaring count123 as a global variable would change its scope but how does that remove the warning? Please guide.