Home / Questions / What is the difference between the local variable and global variable in C?
Explanatory Question

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

👁 1,714 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

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.