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

return 1;<br />

}<br />

}<br />

else {<br />

printf("Not enough memory ‐ calloc failed.\n");<br />

return 1;<br />

}<br />

}<br />

Output:<br />

Free Function:‐<br />

Now allocating more memory...<br />

ptr[0] holds 1<br />

ptr[1] holds 2<br />

ptr[2] holds 4<br />

ptr[3] holds 8<br />

ptr[4] holds 16<br />

ptr[5] holds 32<br />

ptr[6] holds 64<br />

It is used to de‐allocate the previously allocated memory <strong>using</strong> Malloc or Calloc<br />

functions.<br />

When you allocate memory with either malloc() or calloc(), it is taken from the<br />

dynamic memory pool that is available to your program. This pool is sometimes<br />

called the heap, and it is finite. When your program finishes <strong>using</strong> a particular<br />

block of dynamically allocated memory, you should de‐allocate, or free, the<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!