In this article we will be going to discuss very basic topic , local variable and global variable in C language in which following topics are included,
- Local Variable in C
- Example of local Variable in C
- Global Variable in C
- Example of Global Variable in C
Local Variable in C:
A local variable is nothing but, it is also a type of simple variable which is declared within the block of function that function would be a main() function or other block of function.
A local variable is visible and meaningful only inside the functions in which they are declared.They are not know by the other function.
Example of local Variable in C:
int main()
{
int a=5;
int b=6;
int C;
}
here all three integer variable a,b,c are as local variable because they are define in main() function and the value of this variable is valid for only in main() function, other function can't be access this variable.
Global Variable in C:
A global variable in C is nothing but, it also a type of variable which is declared before the main() function such variables are called as global variable in C, and a global variable also called as external variable in C.
A global variable can be used in all the function in the program.it need not be declared in other functions.
Example of Global Variable in C:
int d=10:;
int e=15;
int main()
{
int a=5;
int b=6;
int C;
}
here ' int d ' and ' int e ' are as global variable because they are define outside the main() function and the value of these variable is valid in entire program.
Conclusion:
In this article we have learned about local variable and global variable of C in detail with example, I hope after reading this article you have no any doubt remaining in this topic but, still if you any queries then feel free comment below.
