1<html lang="en"> 2<head> 3<title>calloc - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="bsearch.html#bsearch" title="bsearch"> 10<link rel="next" href="div.html#div" title="div"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="calloc"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="div.html#div">div</a>, 31Previous: <a rel="previous" accesskey="p" href="bsearch.html#bsearch">bsearch</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.11 <code>calloc</code>—allocate space for arrays</h3> 37 38<p><a name="index-calloc-17"></a><a name="index-g_t_005fcalloc_005fr-18"></a><strong>Synopsis</strong> 39<pre class="example"> #include <stdlib.h> 40 void *calloc(size_t <var>n</var>, size_t <var>s</var>); 41 void *_calloc_r(void *<var>reent</var>, size_t <var>n</var>, size_t <var>s</var>); 42</pre> 43 <p><strong>Description</strong><br> 44Use <code>calloc</code> to request a block of memory sufficient to hold an 45array of <var>n</var> elements, each of which has size <var>s</var>. 46 47 <p>The memory allocated by <code>calloc</code> comes out of the same memory pool 48used by <code>malloc</code>, but the memory block is initialized to all zero 49bytes. (To avoid the overhead of initializing the space, use 50<code>malloc</code> instead.) 51 52 <p>The alternate function <code>_calloc_r</code> is reentrant. 53The extra argument <var>reent</var> is a pointer to a reentrancy structure. 54 55 <p><br> 56<strong>Returns</strong><br> 57If successful, a pointer to the newly allocated space. 58 59 <p>If unsuccessful, <code>NULL</code>. 60 61 <p><br> 62<strong>Portability</strong><br> 63<code>calloc</code> is ANSI. 64 65 <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>, 66<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. 67 68 <p><br> 69 70 </body></html> 71 72