所以我有一个棘手的问题需要回答:void f() int *c=(int*)malloc(10); 我想我知道malloc是如何工作的,因为sizeof(int)是4个字节,所以我认为没有足够的空间容纳9个整数,c+9会指向分配内存范围之外的一些内存,并返回一个错误,但是不,程序工作得很好,就像分配了10*sizeof(int)一样。
我想编写一个函数,该函数可以使用目标指针来分配内存并将源复制到其中。0000000000A46E30 = address inside ptr variable c inside function after malloc
000000000061FDE0variable c2 after malloc