Difference between Global and static variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Difference between Global and static variables

The global variable can be accessed anywhere within the program and the static variable is available until the program is exited. I have tried to declare the static variable in the place of global variable (i.e., declared the static variable above the main() ) and i still get the same output as expected and this drives me with a question, is the two variable types are similar in operation ?

16th Jun 2019, 4:45 PM
Dhanesh Sivasamy
Dhanesh Sivasamy - avatar
1 Answer
+ 4
they are almost close to similar the only difference I see is just that the static variable is limited to the scope of the function which it is define, but just like the global it remains intact all through the program, this have been explained vividly, you can just use the search bar you can find more on this
16th Jun 2019, 5:22 PM
✳AsterisK✳
✳AsterisK✳ - avatar