Sponsored Links


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
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

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

    Sponsored Links1



  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    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.

    Sponsored Links

    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.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how many malloc ,calloc and realloc take arguments in c++
    By Vuhelper in forum C++ Programing
    Replies: 0
    Last Post: 06-20-2012, 08:57 PM
  2. Replies: 0
    Last Post: 05-31-2012, 01:51 AM
  3. Replies: 0
    Last Post: 05-31-2012, 01:46 AM
  4. Replies: 0
    Last Post: 05-12-2011, 09:03 PM
  5. Replies: 1
    Last Post: 04-24-2011, 06:28 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.
Online Education | JhelumSoft