Home  
 
  Ask Questions  
 
  Feed Back  
 
  My Questions  
 
  Contact Us  
 
  About Us  
 
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies

  • NEW INTERVIEW QUESTIONS.COM LANGUAGES INTERVIEW QUESTIONS C INTERVIEW QUESTIONS DETAILS


    NewInterviewQuestions.com - Home for World's Largest Interview Questions Website.

    A D V E R T I S E M E N T




    Add to My Questions Add to My Questions | Forward Forward | Print Print


    Question Question Is it better to use malloc() or calloc()?
    Answer Answer Both the malloc() and the calloc() functions are used to allocate dynamic memory. Each operates slightly different from the other. malloc() takes a size and returns a pointer to a chunk of memory at least that big:

    void *malloc( size_t size );

    calloc() takes a number of elements, and the size of each, and returns a pointer to a chunk of memory
    at least big enough to hold them all:

    void *calloc( size_t numElements, size_t sizeOfElement );

    There?s one major difference and one minor difference between the two functions. The major difference is that malloc() doesn?t initialize the allocated memory. The first time malloc() gives you a particular chunk of memory, the memory might be full of zeros. If memory has been allocated, freed, and reallocated, it probably has whatever junk was left in it. That means, unfortunately, that a program might run in simple cases (when memory is never reallocated) but break when used harder (and when memory is reused). calloc() fills the allocated memory with all zero bits. That means that anything there you?re going to use as a char or an int of any length, signed or unsigned, is guaranteed to be zero. Anything you?re going to use as a pointer is set to all zero bits. That?s usually a null pointer, but it?s not guaranteed.Anything you?re going to use as a float or double is set to all zero bits; that?s a floating-point zero on some types of machines, but not on all.

    The minor difference between the two is that calloc() returns an array of objects; malloc() returns one object. Some people use calloc() to make clear that they want an array.


    © NewInterviewQuestions.com


    If you have the better answer, than send it to us. We will display your answer after the approval.
    Answer Answer:*
    Name Name:*
    Email Address Email Address:*
         Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
     


    Rate the above answer. Help us to know about the answer.
    Category Category C Interview Questions
    Rating Rating (4.5) By 27 users
    Added Added 10/22/2004
    Views Views 162416
    Rate it Rate it!
    Free Offers Free Offers: 300 Free Magazines for you. No credit card required. No Shipping Charges. Absolutely Free for 1 Year.

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:


    A D V E R T I S E M E N T





     Sponsors  
    Latest 10 Answers
    Restricted mode is a mode of DB where instance is started and only DBA can access the instance.
    It is nothing but an electronic devices used for connecting any wireless applications.
    SQRW, cmd line, process schedular.
    Moving from one BTS to another BTS with out dropping the call is called HANDOVER but it is only used in GSM, in case of CDMA we use HANDOFF mechanism.
    ALL THE FACTORS WHICH ARE AFFECTING THE HUMAN RELATIONS OF A COMPANY IS UNDER THE DEFINITION OF HUMAN RESOURCE.
    Use Regularexpression Validator and custom the format what you want set to that text box.
    int count1s =0; while(num != 0){ if(num & 1 == 1){ count1s++; } num= num>>1; } printf("%d", count1s);
    use regular expression validation.
    Using datasets,we can get the data and to display we can use the grid view.
    Accounts payable is where the payment is made regarding payment to the invoices/bill.

    Newinterviewquestions.com is a part of Vyom Network. Top



    Copyright © 2009, newinterviewquestions.com. All rights reserved Privacy Policy | Terms and Conditions

    Page URL: http://www.newinterviewquestions.com/interview/1001/Default.asp?cachecommand=bypass


    Download Yahoo Messenger | Web Hosting