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

Local variableGlobal variable
Declared inside a function or blockDeclared outside all functions
Can be used only in that blockCan be used in all functions
Default value is garbageDefault value is 0
Removed when the function endsLives until the program ends

Try to use local variables as much as possible. Global variables can be changed from anywhere, so bugs are hard to find. See Scope and Storage Classes.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.