Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The standard C library declares the function calloc() as follows:</p> <p><code>void *calloc(size_t elements, size_t sz);</code><br></p> <p>calloc() allocates space for an array of elements, each of which occupies sz bytes of storage. The space of each element is initialized to binary zeros. In other words, calloc() is similar to malloc(), except that it handles arrays of objects rather than a single chunk of storage and that it initializes the storage allocated. The following example allocates an array of 100 int's using calloc():</p> <pre><code>int * p = (int*) calloc (100, sizeof(int)); </code></pre> <hr> <h3>NAME</h3> <blockquote> <pre><code>calloc - a memory allocator </code></pre> </blockquote> <h3>SYNOPSIS</h3> <blockquote> <pre><code>#include &lt;stdlib.h&gt; void *calloc(size_t nelem, size_t elsize); </code></pre> </blockquote> <h3>DESCRIPTION</h3> <blockquote> <p>The <strong><code>calloc()</code></strong> function allocates memory for an array of <strong><em>nelem</em></strong> elements of <strong><em>elsize</em></strong> bytes each and returns a pointer to the allocated memory. The memory is set to zero. If <strong><em>nelem</em></strong> or <strong><em>elsize</em></strong> is 0, then <strong><code>calloc()</code></strong> returns either NULL, or a unique pointer value that can later be successfully passed to <strong><code>free()</code></strong>.</p> </blockquote> <h3>RETURN VALUE</h3> <blockquote> <p>The <strong><code>calloc()</code></strong> function returns a pointer to the allocated memory that is suitably aligned for any kind of variable. On error, it returns NULL. NULL may also be returned by a successful call with <strong><em>nelem</em></strong> or <strong><em>elsize</em></strong> equal to zero.</p> </blockquote> <hr> <h2>Wikipedia</h2> <ul> <li><a href="http://en.wikipedia.org/wiki/C_dynamic_memory_allocation" rel="nofollow">C dynamic memory allocation</a></li> </ul> <h2>References</h2> <ul> <li><a href="http://en.cppreference.com/w/c/memory/calloc" rel="nofollow">calloc - cppreference.com</a></li> <li><a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html" rel="nofollow">calloc - The Open Group Base Specifications Issue 7</a></li> <li><a href="http://manpages.ubuntu.com/manpages/precise/man3/malloc.3.html" rel="nofollow">Ubuntu Manpage: malloc, free, calloc, realloc - Allocate and free dynamic memory</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/hk1k7x6x.aspx" rel="nofollow">Memory Allocation Routines - C Run-Time Library Reference (Visual Studio 2012)</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/3f8w183e.aspx" rel="nofollow">calloc - C Run-Time Library Reference (Visual Studio 2012)</a></li> </ul> <h2>Related Tags</h2> <ul> <li><a href="/questions/tagged/malloc" class="post-tag" title="show questions tagged 'malloc'" rel="tag">malloc</a></li> <li><a href="/questions/tagged/realloc" class="post-tag" title="show questions tagged 'realloc'" rel="tag">realloc</a></li> <li><a href="/questions/tagged/free" class="post-tag" title="show questions tagged 'free'" rel="tag">free</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload