📄 stdmem_details.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>Standard C Memory</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> <a href="stdmem.html">Standard C Memory</a> -> Details</td> </tr> </table> <h1>Standard C Memory</h1> <hr> <h2><a name="calloc">calloc</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> void *calloc( size_t num, size_t size );</pre> </td> </tr> </table> <p>The calloc() function returns a pointer to space for an array of <i>num</i> objects, each of size <i>size</i>. calloc() returns NULL if there is an error.</p> <i>Related topics:</i><br> <strong><a href="#free">free()</a>, <a href="#malloc">malloc()</a>, and <a href= "#realloc">realloc()</a>.</strong> <hr> <h2><a name="free">free</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> void free( void *ptr );</pre> </td> </tr> </table> <p>The free() function deallocates the space pointed to by <i>ptr</i>, freeing it up for future use. <i>ptr</i> must have been used in a previous call to <a href="#malloc">malloc()</a>, <a href= "#calloc">calloc()</a>, or <a href="#realloc">realloc()</a>. An example:</p><pre> typedef struct data_type { int age; char name[20]; } data; data *willy; willy = (data*) malloc( sizeof(willy) ); ... free( willy );</pre> <i>Related topics:</i><br> <strong><a href="#calloc">calloc()</a>, <a href="#malloc">malloc()</a>, and <a href= "#realloc">realloc()</a>.</strong> <hr> <h2><a name="malloc">malloc</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> void *malloc( size_t size );</pre> </td> </tr> </table> <p>The function malloc() returns a pointer to a chunk of memory of size <i>size</i>, or NULL if there is an error. The memory pointed to will be on the heap, not the stack, so make sure to <a href= "#free">free</a> it when you are done with it. An example:</p><pre> typedef struct data_type { int age; char name[20]; } data; data *bob; bob = (data*) malloc( sizeof(data) ); if( bob != NULL ) { bob->age = 22; strcpy( bob->name, "Robert" ); printf( "%s is %d years old\n", bob->name, bob->age ); } free( bob );</pre> <i>Related topics:</i><br> <strong><a href="#free">free()</a>, <a href="#realloc">realloc()</a>, and <a href= "#calloc">calloc()</a>.</strong> <hr> <h2><a name="realloc">realloc</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> void *realloc( void *ptr, size_t size );</pre> </td> </tr> </table> <p>The realloc() function changes the size of the object pointed to by <i>ptr</i> to the given <i>size</i>. <i>size</i> can be any size, larger or smaller than the original. The return value is a pointer to the new space, or NULL if there is an error.</p> <i>Related topics:</i><br> <strong><a href="#free">free()</a>, <a href="#malloc">malloc()</a>, and <a href= "#calloc">calloc()</a>.</strong> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -