我有以下情况。我的目标是让a和b使它们都指向相同的记忆。但条件是它们都是指针。我该怎么做?指针结构
struct myStruct
{
struct anotherStruct* anoStrct;
};
main()
{
struct myStruct *a=(struct myStruct*)malloc(sizeof(struct myStruct));
struct myStruct *b=(struct myStruct*)malloc(sizeof(struct myStruct));
a=b;
}
在你的代码中,你第一个'malloc'(原来的'a')丢失的内存区域是内存泄漏。使用内存泄漏检测器(例如Linux上的valgrind)和调试器。 – 2013-04-11 07:44:10