一、malloc函数分析
1.函数原型
void * malloc(size_t size);
2.Function(功能)
Allocates a block of size bytes of memory, returning a pointer to the beginning of the block
译:在内存中分配 size 个字节的空间,返回一个指向”内存空间开头“的指针(指针类型为void *)。
3.Parameters
size
size of the memory block,in bytes
4.Return Value
On success, a pointer to the memory block allocated by the function.
The type
of this pointer is always void*, which can be cast to the desired type
of data pointer in order to be dereferenceable.
If the function failed to
allocate the requested block of memory, a null pointer is returned.
译:申请内存成功,返回一个指向”被函数分配的内存空间“的指针。
这个指针的类型是void *(指向任意类型的指针),它可以被转换为期望类型的数据指针,以便能够解除引用。
如果函数分配被要求的内存空间失败,则返回一个空指针(NULL)
5.Example