C: Global ,Static variables understanding
Posted
by pavun_cool
on Stack Overflow
See other posts from Stack Overflow
or by pavun_cool
Published on 2010-03-22T10:39:11Z
Indexed on
2010/03/22
10:41 UTC
Read the original article
Hit count: 231
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.
© Stack Overflow or respective owner