free

来自cppreference.com
< c | memory

Defined in header <stdlib.h>
void free( void* ptr );
释放的空间分配malloc()calloc()realloc()ptr是空指针,这个函数一无所有
Original:
Deallocates the space previously allocated by malloc(), calloc() or realloc(). If ptr is null-pointer, the function does nothing.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ptr的行为是不确定的,如果不匹配,返回一个指针早malloc()calloc()realloc()。此外,该行为是未定义的,如果已经被释放的内存区域所提到的ptrfree()realloc()已经被称为ptr为参数,并没有呼叫malloc()calloc()realloc()导致指针等于ptr后来.
Original:
The behavior is undefined if ptr does not match a pointer returned earlier by malloc(), calloc() or realloc(). Also, the behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, free() or realloc() has already been called with ptr as the argument and no calls to malloc(), calloc() or realloc() resulted in a pointer equal to ptr afterwards.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 参数

ptr -
要解除分配的存储器的指针
Original:
pointer to the memory to deallocate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 返回值

(无)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 为例

#include <stdlib.h>
 
int main(int argc, char* argv[]) {
  int* ptr = (int*) malloc( sizeof(int) );
  free(ptr);
  return 0;
}


[编辑] 另请参阅