Global variables are defined outside. They hold their value throughout the lifetime of your program. A global variable can be accessed by any function. It is available for use throughout your entire program after its declaration. This is called static duration. Variables with static duration are sometimes called static variables.
There are mainly two types of variable scopes:
- Your first part of the code is local variable for main(). You cant use int x outside of main(){}
- Second one is called global variable
Also unlike local variables, which are uninitialized by default, static variables are zero-initialized by default.