Sie sind auf Seite 1von 2

13/04/12

Search:

calloc - C++ Reference


Go CLibrar cstdlib(stdlib.h) calloc register

Reference C++
Information Documentation Reference Articles Forum

function

calloc
vialc(sz_u,sz_ie) od*cloietnmietsz Allocatespaceforarra inmemor Allocatesablockofmemoryforanarrayofnumelements,eachofthemsi ebyteslong,andinitializesallitsbitstozero. Reference Theeffectiveresultistheallocationofanzeroinitializedmemoryblockof(num*si e)bytes.

CLibrar IOstreamLibrar Stringslibrar STLContainers STLAlgorithms Miscellaneous

Parameters
num Numberofelementstobeallocated. CLibrar size Sizeofelements.

cassert(assert.h) cct pe(ct pe.h) cerrno(errno.h) cfloat(float.h) ciso646(iso646.h) climits(limits.h) clocale(locale.h) cmath(math.h) csetjmp(setjmp.h) csignal(signal.h) cstdarg(stdarg.h) cstddef(stddef.h) cstdio(stdio.h) cstdlib(stdlib.h) cstring(string.h) ctime(time.h)

ReturnValue

Apointertothememoryblockallocatedbythefunction. Thetypeofthispointerisalwaysv i * o d ,whichcanbecasttothedesiredtypeofdatapointerinordertobedereferenceab Ifthefunctionfailedtoallocatetherequestedblockofmemory,aN L pointerisreturned. UL

E ample
1/ a l c e a p e * *cloxml/ 2# n l d s d o h icue<ti.> 3# n l d s d i . > icue<tlbh 4 5i t m i ) nan( 6{ 7 i t i n n, 8 i t * p a a nDt 9 p i t " m u t o u b r o b n e e : " rnf(Aonfnmesteetrd) 1 saf(%"&) 0 cn"d,i 1 paa=(n*alc(,iefit) 1 Dtit)cloiszo(n) 1 ipaa=ULxt() 2 f(Dt=NL)ei1 1 fr(=<+) 3 on0nin+ 1 { 4 1 pit"neubr#d,) 5 rnf(Etrnme%:"n 1 saf(%"&Dt[] 6 cn"d,paan) 1 7 1 pit"oaeetrd) 8 rnf(Yuhvnee:" 1 fr(=<+)pit"d"paan) 9 on0nin+rnf(%,Dt[] 2 fepaa 0 re(Dt) 2 rtr 1 eun0 2 2

cstdlib(stdlib.h)
functions: abort abs atexit atof atoi atol bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs mbtowc qsort rand realloc srand strtod strtol strtoul system wcstombs wctomb functions(nonstandard): itoa macros: EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX t pes: div_t ldiv_t size_t

Thisprogramsimplystoresnumbersandthenprintsthemout.Butthenumberofitemsitstorescanbeadaptedeachtime isexecutedbecauseitallocatesasmuchdynamicmemoryasneededduringruntime.

Seealso
free malloc realloc Deallocatespaceinmemory(function) Allocatememoryblock(function) Reallocatememoryblock(function)

www.cplusplus.com/reference/clibrar /cstdlib/calloc/

1/2

13/04/12

calloc - C++ Reference


Homepage|Privacypolicy|oldlayout cplusplus.com,20002012Allrightsreservedv3.0 Spottedanerror?contactus

www.cplusplus.com/reference/clibrar /cstdlib/calloc/

2/2

Das könnte Ihnen auch gefallen