Home
menubar
rss_feed

Previous Reference C++ Reference <cstdlib> Next Reference




C++ Reference: calloc()





calloc()


Declaration

void* calloc( size_t qCount, size_t qSize);

Description

Allocates an array of elements and initializes them to zero. The argument "qCount" is the number of elements allocated and "qSize" is the size of each element. Th function returns a void pointer to the allocated array.

Example

#include <iostream>
#include <cstdlib>

int main() {
    using namespace std;

    int* ipArray = (int*)calloc(7, sizeof(int));
    // Output the elements to verift that they have been set to zero.
    for (int iIndex = 0; iIndex < 7; ++iIndex) {
        cout << "  " << ipArray[iIndex];
    }
    cout << endl;
    // Deallocate the memory
    free(ipArray);

    return 0;
}


Output:








Previous Reference C++ Reference <cstdlib> Next Reference




Home | Reference | Play Games! | Blog | Forum | Site Map | Contact Us


shadow bottom image