A variable that is declared inside the function or block is called a local variable. It must be declared at the start of the block.
Example:
void function(){
int x=10;//local variable
}
A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions. It must be declared at the start of the block.
Example:
void function(){
int x=10;//local variable
}
A variable that is declared with the static keyword is called static variable. It retains its value between multiple function calls.
Example:
void function(){
int x=10;//local variable
}
All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using auto keyword
Example:
void main(){
int x=10;//local variable (also automatic)
auto int y=20;//automatic variable
}
We can share a variable in multiple C source files by using an external variable. To declare an external variable, you need to use extern keyword
Example:
extern int x=10;//external variable (also global)