#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void main() {
int *p = (
int *)
malloc(
2 *
sizeof(
int));
int *t = p +
1;
printf(
"p的值:%d\n", p);
printf(
"t的值:%d\n", t);
p = (
int *)realloc(p,
6 *
sizeof(
int));
printf(
"p的值:%d\n", p);
printf(
"t的值:%d\n", t);
}
p在realloc后整体挪窝了,它不管他的好伙伴t了,t还在原地傻傻地等待。但是p还不算特别坏,它没有带走t所指的内容,相当于是p 又复制了一份走了。
转载请注明原文地址: https://www.6miu.com/read-2620377.html