C Programming Questions and Answers

Questions Index

Question: Differentiate between local variable and global variable.

Answer:

Local Variable

Variables declared within a function, become local to the function.
Local variables have local scope. They can only be accessed within the function.
Local variables are created when a method starts, and deleted when the method is completed.

Global Variable

A variable that is declared outside any function is known as a global variable.
The scope of such a variable extends till the end of the program. These variables are available to all functions which follow their declaration.
It should be defined at the beginning, before any function is defined.