| |
|
Variables Types in C
As per i define below there are 5 types of variables available in C:
(1)local variable
(2)global variable
(3)static variable
(4)automatic variable
(5)external variable
(1)Local Variable
When we declared variable inside the function or block is called a local variable. And we usually declared at the start of the block.
We must have to initialize the local variable before it is used.
(2)Global Variable
When we declared variable outside function or block is called global variable. And any of function can change value of global variable. And it is available to all the functions. And we usually define at the start of the block.
(3)Static Variable
When we declare variable with static keyword is called static variable. It retains its value between multiple function calls.
If we call function many times the local variable will print the same value for each and every function. In above example local variable alwasy remains 11. But when we declare static variable then it will be incremented in each function call 11,12,13 and so on.
(4)Automatic 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.
(5)External Variable
When we need to share a variable in multiple C source file then we need to use exteranl keyword. Below is the example to declare the extern variable.
Below we have define two file one to declare external variable. and in 2nd file we use external variable .
| |
|
|
|
|