0
What does local variables be like ? What's its use in c++ ??
2 odpowiedzi
+ 4
#include <iostream>
using namespace std;
int g; //global variable.
int main()
{
int l; // local variable.
return 0;
}
A local variable can only be use in its own block.
A global variable can be use in all functions from its class.
+ 2
Like what Max stated, a local variable can only be used inside its own block {} . The use of it is to prevent outside blocks from using some variables accidentally or changing it's value.