10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

Like malloc, calloc will return a void pointer if the memory allocation was<br />

successful, else it'll return a NULL pointer.<br />

This example shows you how to call calloc and also how to reference the<br />

allocated memory <strong>using</strong> an array index. The initial value of the allocated<br />

memory is printed out in the for loop.<br />

#include <br />

#include <br />

/* required for the malloc, calloc and free functions */<br />

int main() {<br />

float *calloc1, *calloc2, *malloc1, *malloc2;<br />

int i;<br />

calloc1 = calloc(3, sizeof(float)); /* might need to cast */<br />

calloc2 = calloc(3, sizeof(float));<br />

malloc1 = malloc(3 * sizeof(float));<br />

malloc2 = malloc(3 * sizeof(float));<br />

if(calloc1!=NULL && calloc2!=NULL && malloc1!=NULL && malloc2!=NULL) {<br />

for(i=0 ; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!