【发布时间】:2016-05-26 15:07:32
【问题描述】:
以这段代码为例:
Struct* allocSomething(void) {
int n;
Struct *something = malloc(n*sizeof(Struct));
return something;
}
Struct* reallocSomething(Struct **s) {
int n;
Struct *something = realloc(*s, (n*sizeof(int)) - 1 * sizeof(Struct));
return something;
}
int main() {
Struct *point = allocSomething();
//code does something...
point = reallocSomething();
free(point);
}
我的问题是,在调用reallocSomething 之后,point 仍然与allocSomething 返回的地址相同?比如point有地址0x01,当这个指针被reallocSomething重新分配时,那个地址还是0x01吗?
【问题讨论】:
-
编译器警告是你的朋友。启用并注意他们!并阅读文档。