Answer:
Global variables:
1. It is declare outside of all functions.
2. Cannot be declare the two global variable with same name.
3. It can be used in any where in the program, the is no problem with scope.
Local variables:
1. It is declare inside the functions.
2. Can be declare the two or more local variable with same name in the different functions.
3. It is available until that functions are executed.
Step-by-step explanation:
Global variables are declare outside of all function,, we can access that variable anywhere in the program
for example:
int num = 10;
int main(){
statement;
fun(){
statement;
}
}
The variable is outside of all functions. So, it is a global variable.
It is not declare in the function or block, this is reason it has no problem with availability. it is available until the program is executed.
Other side, local variable is declare in the function.
for example:
int main(){
int num = 10;
statement;
fun(){
int num = 10;
statement;
}
}
Here, the variable num is local variable and it can be more than one time with same name but in the different function.
it is available untill that function executed.