Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
Scope of varieble in simple form determines when a variable is "alive" and can be "seen" by who withouth passing the variable. if you declare a global varieble the varieble "lives" until the program ends. And can be seen by all functions. if you declare a local variable in main the variable lives until program ends. And only can be seen by main (if you not pass somehow) local variable in function is almost the same as local variable in main. The difference is the variable will live until end of function. the exception is when you declare a varieble as static in function. the variable will live until the end of program. Still will only be seen by the function.
26th Oct 2018, 11:06 PM
Anya
Anya - avatar