+ 1

What Different And Function Between Global And Local Variable C++

iam not undertestand for what is global variable. someone can explain with simple answer ?.

21st May 2017, 2:42 PM
Muhammad Syabani Falif
Muhammad Syabani Falif - avatar
3 Réponses
+ 10
Most variables have a limited scope in which they are accessible (within the function where they are declared, but not in functions that call or are called by that function). A global variable is declared outside of any function, and is accessible to any part of the program. Typically they will be declared just after the #include statements. That can make some things easier to write, but global variables can make for debugging headaches if you are not very careful with them. Personally, I avoid them whenever possible. Did that help?
21st May 2017, 2:51 PM
Jim
Jim - avatar
+ 9
Glad to have helped!
21st May 2017, 3:05 PM
Jim
Jim - avatar
+ 2
iam undertestand now :D thanks jim
21st May 2017, 2:52 PM
Muhammad Syabani Falif
Muhammad Syabani Falif - avatar