calloc Function


The calloc ( ) function is also used to allocate main memory dynamically. It provides access to the C memory heap, which is available for dynamic allocation of variable sized blocks of memory. Its declaration is of the form

                                               void *calloc ( size_t nitem, size_t size );

Here size_t and size have the same meaning as discussed in malloc ( ). The nitem corresponds to number of items you want to save in the allocated space like malloc ( ), on success calloc ( ) also returns pointer to the newly allocated block and returns NULL on failure. However, unlike malloc ( ) it takes two arguments and memory space allocated by calloc ( ) is always initialized to 0.





Previous                                                                                    Next


Powered by Blogger.