Sponsored Links


+ Reply to Thread
Results 1 to 2 of 2

Thread: how we used the 1-calloc Function 2- malloc Function 3- free () 4- realloc Function i

  1. #1
    Super Moderator Vuhelper's Avatar Users Flag!
    Join Date
    Apr 2011
    Posts
    7,748

    Icon51 how we used the 1-calloc Function 2- malloc Function 3- free () 4- realloc Function i

    Sponsored Links


    Define that how we used the 1-calloc Function 2- malloc Function 3- free () 4- realloc Function in C and C++ 2012- 14


    Sponsored Links

  2. #2
    Super Moderator Vuhelper's Avatar Users Flag!
    Join Date
    Apr 2011
    Posts
    7,748
    Calloc malloc and realloc are use for dynamic memory allocation. Mainly there are two types calloc and malloc. Realloc is the provide the litter variation in malloc.

    calloc take two argument i.e. calloc(m,n) where first argument is how much space you require in term of number of elements and 2nd argument is space in term of size of each element
    For example

    calloc(1000,sizeof(int));

    where 1000 is total space that is allocated from heap and it is of size integer.
    The main benefit of doing memory allocation through calloc that memory is automatically initialized with 0.

    malloc take one argument i.e. malloc(n) wher n is number of bytes required.
    For example

    malloc(1000*(sizeof(int)));

    Where again 1000 require space that is allocated from heap and it is multiplied with integer.

    If a pointer has already been allocated memory using malloc and later this allocated memory needs to be expanded for some reason, the realloc function is used. It will add the consecutive memory spaces to the existing if available, otherwise it will allocate whole new space for the same pointer. free is use to de-allocation the memory which we allocation for our use.

    As I already told you that alloc malloc and realloc are use for dynamic memory allocation once you allocation memory using any of the method, you must use free to de-allocate the memory.

    Yes you are right these function are from C but C++ also support these functions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. What are the function of IO ports in C++
    By Vuhelper in forum C++ Programing
    Replies: 0
    Last Post: 05-30-2012, 08:27 PM
  2. Replies: 0
    Last Post: 05-12-2011, 04:03 PM
  3. friend function in c++
    By saneha in forum C++ Programing
    Replies: 1
    Last Post: 05-02-2011, 12:18 PM
  4. Replies: 1
    Last Post: 04-24-2011, 01:28 PM
  5. Replies: 0
    Last Post: 04-24-2011, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Pknews |Vugurus|Online Education