0 votes
in C Plus Plus by
What is the difference between the local and global variables in C?

1 Answer

0 votes
by

Local variables are declared inside a block or function but global variables are declared outside the block or function to be accessed globally.

Local Variables

Global Variables

Declared inside a block or a function.Variables that are declared outside the block or a function.
By default, variables store a garbage value.By default value of the global value is zero.
The life of the local variables is destroyed after the block or a function.The life of the global variable exists until the program is executed.
Variables are stored inside the stack unless they are specified by the programmer.The storage location of the global variable is decided by the compiler.
To access the local variables in other functions parameter passing is required.No parameter passing is required. They are globally visible throughout the program.
 

Related questions

0 votes
asked Jan 6 in C Plus Plus by GeorgeBell
0 votes
asked Jan 11 in C Plus Plus by GeorgeBell
...