Lecture : 11 Local, Global and Static variable Local variable:- Variables that are defined with in a body of function or block. The local variables can be used only in that function or block in which they are declared. Same variables may be used in different functions such as function() { int a,b; function 1(); } function2 () { int a=0; b=20; } Global variable:- the variables that are defined outside of the function is called global variable. All functions in the program can access and modify global variables. Global variables are automatically initialized at the time of initialization. Example: #include<stdio.h> void function(void); void function1(void); void function2(void); int a, b=20; void main() { printf(“inside main a=%d,b=%d \n”,a,b); function(); function1(); function2(); } function() { Prinf(“inside function a=%d,b=%d\n”,a,b); } function 1() { prinf(“inside function a=%d,b=%d\n”,a,b); } function 2() { pri...
Comments
Post a Comment