例如,当我在 while 循环之外分配内存时,可以在其中释放它吗?这两个代码是否等效?
int* memory = NULL;
memory = malloc(sizeof(int));
if (memory != NULL)
{
memory=10;
free(memory);
}
int* memory = NULL;
memory = malloc(sizeof(int));
if (memory != NULL)
{
memory=10;
}
free(memory);