How many memeory does malloc will going to assign with defination ?

This is a discussion on How many memeory does malloc will going to assign with defination ? within the C Programming forums, part of the General Programming Boards category; Hello, what is the default return type of malloc. and how mamy memory malloc will going to assign with this ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    17

    How many memeory does malloc will going to assign with defination ?

    Hello,

    what is the default return type of malloc.
    and how mamy memory malloc will going to assign with this atatement

    Code:
    void * ptr;
    
    ptr = malloc(10);
    And also how we can calculate how many memeory is assign by malloc in case if we want to check does malloc has allocate the required amount of memory or not.

    Thanks,
    Gunjan

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,646
    malloc()'s return type is pointer to void (i.e. void *). The argument of malloc() specifies how much is to be allocated by that call. malloc() returns NULL if the allocation fails.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by gunjansethi View Post
    Hello,

    what is the default return type of malloc.
    and how mamy memory malloc will going to assign with this atatement

    Code:
    void * ptr;
    
    ptr = malloc(10);
    And also how we can calculate how many memeory is assign by malloc in case if we want to check does malloc has allocate the required amount of memory or not.

    Thanks,
    Gunjan
    The return type of malloc is void* ... which can be assigned to any pointer.

    You don't/can't check how much memory is assigned to a pointer, you have to keep track of that yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help me as fast as possible
    By Xbox999 in forum C Programming
    Replies: 5
    Last Post: 11-30-2009, 06:53 PM
  2. malloc + segmentation fault
    By ch4 in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 04:46 PM
  3. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 12:26 PM
  4. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM
  5. Linked list question....again
    By dP munky in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2003, 05:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21