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 />

}<br />

else {<br />

printf("Not enough memory\n");<br />

return 1;<br />

}<br />

}<br />

Output:<br />

calloc1[0] holds 0.00000, malloc1[0] holds ‐431602080.00000<br />

calloc2[0] holds 0.00000, malloc2[0] holds ‐431602080.00000<br />

calloc1[1] holds 0.00000, malloc1[1] holds ‐431602080.00000<br />

calloc2[1] holds 0.00000, malloc2[1] holds ‐431602080.00000<br />

calloc1[2] holds 0.00000, malloc1[2] holds ‐431602080.00000<br />

calloc2[2] holds 0.00000, malloc2[2] holds ‐431602080.00000<br />

Realloc Function:‐<br />

Now suppose you've allocated a certain number of bytes for an array but later<br />

find that you want to add values to it. You could copy everything into a larger<br />

array, which is inefficient, or you can allocate more bytes <strong>using</strong> realloc, without<br />

losing your data.<br />

realloc takes two arguments. The first is the pointer referencing the memory.<br />

The second is the total number of bytes you want to reallocate.<br />

Passing zero as the second argument is the equivalent of calling free.<br />

Once again, realloc returns a void pointer if successful, else a NULL pointer is<br />

returned.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 68 ‐

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

Saved successfully!

Ooh no, something went wrong!