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.

}<br />

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

for(i=number ; i>0 ; i‐‐) {<br />

printf("%d\n", *(ptr+(i‐1))); /* print out in reverse order */<br />

}<br />

free(ptr); /* free allocated memory */<br />

return 0;<br />

}<br />

else {<br />

printf("\nMemory allocation failed ‐ not enough memory.\n");<br />

return 1;<br />

}<br />

}<br />

Output if I entered 3:<br />

Calloc Function:‐<br />

How many ints would you like store? 3<br />

2<br />

1<br />

0<br />

Calloc is similar to malloc, but the main difference is that the values stored in<br />

the allocated memory space is zero by default. With malloc, the allocated<br />

memory could have any value.<br />

calloc requires two arguments. The first is the number of variables you'd like to<br />

allocate memory for. The second is the size of each variable.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!