0

What does local variables be like ? What's its use in c++ ??

2nd Dec 2016, 12:15 AM
N.Guy
N.Guy - avatar
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.
2nd Dec 2016, 12:46 AM
Max_N
Max_N - avatar
+ 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.
2nd Dec 2016, 3:19 AM
Wen Qin
Wen Qin - avatar