What is the difference between the local variable and global variable in C?

C Programming Language >   Variable in C Language >   Global variables in C  

Long Question

1673


Answer:

Following are the differences between a local variable and global variable:

Basis for comparison Local variable Global variable
Declaration A variable which is declared inside function or block is known as a local variable. A variable which is declared outside function or block is known as a global variable.
Scope The scope of a variable is available within a function in which they are declared. The scope of a variable is available throughout the program.
Access Variables can be accessed only by those statements inside a function in which they are declared. Any statement in the entire program can access variables.
Life Life of a variable is created when the function block is entered and destroyed on its exit. Life of a variable exists until the program is executing.
Storage Variables are stored in a stack unless specified. The compiler decides the storage location of a variable.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.