while i was learning about global variables I did some trials and found one problem. Here goes my code.
int cows = 10; //global variable
void farm1()
{
int cows;
cout<<"in farm1, cows="<<cows<<endl;
cows++;
}
int main()
{
//cout<<"in main, cows="<<cows<<endl;
farm1();
//cout<<"back in main, cows="<<cows<<endl;
}
Here line 6 prints some garbage value as expected. But when I uncomment lines 12 and 14, line 6 prints 10. Can somebody please explain why?