C: Global ,Static variables understanding
- by pavun_cool
Hi All,
In following program . I have one doubt. I have declared one global variable . I am
printing the address of the global variable in the function . It is giving me same address
when I am not changing the value of global . If I did any changes in the global variables
It is giving me different address why...........? Like that it is happening for static also.
#include<stdio.h>
int global=10 ; // Global variables
void function();
main()
{
global=20;
printf ( " %p \n" , global ) ;
printf ( " Val: %d\n", global ) ;
function();
new();
}
void function()
{
global=30;
printf ( " %p \n" , global ) ;
printf ( " Val: %d\n", global ) ;
}
Thanks.