|
[code:1]
/*test.c ,by richard*/
void f();
void g();
void h();
void h_1();
void h_2();
int globle=3;
int main(void)
{
/*I DO this ,wanting to know which one of malloc and sbrk do his job
in the data segment.The man page says that it's the sbrk().and malloc
in the heap segment.
*/
printf("addr of globle:%x \n\n",&globle);
printf("main:%x f:%x g:%x\n\n"main,f,g);
printf("here you will see that the j,which is not valued,get the value of
i,which is in the previous call\n");
f();
g();
printf("\n sbrk(0):%x\n",sbrk(0));
printf("\n malloc(0):%x\n\n",malloc(0));
printf("now see how the stack increase\n ");
h();
printf("now see how the heap change\n");
/*which one do his job in the heap segment,malloc or sbrk() and why the returned value by malloc changed like that?*/
printf("malloc(2):%x malloc(2):%x\n",malloc(2),malloc(2));
printf("malloc(sizeof(char))twice:%x%x\n",malloc(sizeof(char)),malloc(sizeof(char)));
printf("sbrk(0):%x sbrk(2);%x sbrk(2):%x\n",sbrk(0),sbrk(2),sbrk(2));
}
void g(){
int j;//not valued
printf("j:%d addr of j:%x",j,&j);
}
void h(){
int k;//not valued
printf(" addr of k:%x",&k);
h_1();
}
void h_1(){
int k;//not valued
printf(" addr of k:%x",&k);
h_2();
}
void h_2(){
int k;//not valued
printf(" addr of k:%x",&k);
}
[/code:1]
/*大家讨论一下运行结果。本来我想看一下堆栈的上下限,弄个堆栈益处的,单没有把握住运行时内存,大家一起讨论一下*/ |
|