Monday, April 25, 2016

Variable Scope





Global Variables : 

As you notice in the next example x defined one time globally then used in function() and main(). 


Example : 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <stdlib.h>

int x=0;

int function (){

x++;

return x;
}


int main()
{
function () ;
printf("X=%d",x);
    return 0;
}

Ouptut : 






Local Variables : 





Share this

0 Comment to "Variable Scope "

Post a Comment