我对声明有疑问
p = my_malloc(4);
my_malloc 有一个名为 p 的本地指针,当函数返回该指针的地址时将被释放。那么 main 中的 int* p 是如何保存函数返回的地址的呢?当一个函数返回时,它使用的地址可能会或可能不会被其他函数或进程使用。那么下面的程序是未定义的行为吗?
#include<stdio.h>
#include<unistd.h>
void* my_malloc(size_t size){
 void *p;
 p = sbrk(0); 
 p = sbrk(size); // This will give the previous address
 //p = sbrk(0); // This will give the current address
 if(p != (void *)-1){
   printf("\n address of p : 0x%x \n",(unsigned int)p);
 }
 else{
  printf("\n Unable to allocate memory! \n");
  return NULL;
 }
 return p;
}
int main(){
 int* p;
 p = my_malloc(4);
 printf("\n address of p : 0x%x \n",(unsigned int)p);
}