Think the following code:
struct node{
char name[100];
int *p ;
};
main()
{
struct mode test[4];
int i = 0;
//case 1
for ( ; i < 4; i++) {
{static int name; test[i].p = &name; printf("p %p\n", &name);}
}
//case2
{static int name; test[0].p = &name; printf("p %p\n", &name);}
{static int name; test[1].p = &name; printf("p %p\n", &name);}
{static int name; test[2].p = &name; printf("p %p\n", &name);}
{static int name; test[3].p = &name; printf("p %p\n", &name);}
return 0;
}
Case1:
Using object to print infos, i can find only name.So the all address of name are the same;
Case2:
There are four name parameters in .data section.So the address of name are different.
Why?How to avoid this the case1?
If someone know this, please tell me,.