#include <iostream>
using namespace std;
int my_variable = 12;
void cappy()
{
std::cout<<"value is"<< my_variable<<endl;
}
int main()
{
std::cout<< my_variable<<endl;
cappy();
}
this c++ code work and returns:
12
value is12
but whereas :
#include <iostream>
using namespace std;
int my_variable = 12;
int main()
{
std::cout<< my_variable<<endl;
cappy();
}
void cappy()
{
std::cout<<"value is"<< my_variable<<endl;
}
this code returns an error:
cpp: In function ‘int main()’:
cpp:8:7: error: ‘cappy’ was not declared in this scope
why is this so? does location of functions matter in c++?