What is the difference between local and global variables in C?
Local variable
Global variable
Declared inside a function or block
Declared outside all functions
Can be used only in that block
Can be used in all functions
Default value is garbage
Default value is 0
Removed when the function ends
Lives 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.