Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:51:42+00:00 2026-05-13T18:51:42+00:00

What is the advantage of zeroing out memory (i.e. calloc() over malloc() )? Won’t

  • 0

What is the advantage of zeroing out memory (i.e. calloc() over malloc())? Won’t you change the value to something else anyways?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:51:42+00:00Added an answer on May 13, 2026 at 6:51 pm

    There are two camps: one says that initializing variables when they are declared helps find bugs. The people in this camp make sure everything they declare is initialized. They initialize pointers to NULL, ints to 0, etc. The idea is that everything is determinate, and when they see a NULL-pointer in a debugger, they immediately know it wasn’t set properly. It can also help your program crash during testing because of NULL-pointer dereferencing rather than mysteriously crashing in production runs.

    The other camp says that initializing variables at declaration makes things harder to debug, because now a compiler can’t warn you about variables “used without being set”.

    Without telling you my personal preference1: if you belong to the first camp, you would want to calloc() instead of malloc(). If you belong to the second camp (which apparently you do) then you prefer malloc() over calloc().

    Now there are two exceptions:

    • If you belong to the “initialize everything” camp, you don’t calloc() but malloc() because you are initializing floating-point numbers or pointers, and you know that all bits zero doesn’t necessarily mean 0 for them. Or, you don’t want the extra overhead.
    • If you belong to the “set when you need to” camp, you may want to calloc() when you are allocating some data and want it to be all zeroes. For example, if you want to calculate the row-wise sum of an n by m dynamically allocated int data.

    1 You can see my answers to many of the questions here on SO to see which camp I belong to :-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the advantage of using these different frameworks (TouchXML, KissXML, etc) as compare
Extending UserPrincipal to take advantage of its built-in properties... running into an issue when
What is the advantage of intercepting a request for an ASP.Net application at the
Is there any advantage of running Visual Studio 2010 on Windows 7 instead of
Possible Duplicate: Biggest advantage to using ASP.Net MVC vs web forms maybe it feels
Possible Duplicate: Biggest advantage to using ASP.Net MVC vs web forms I'm soon gonna
My question is there really an advantage by placing each webpage in it's own
I am trying to take advantage of autoloading in PHP. I have various classes
I'm trying to put together an association that takes advantage of Mongo's document subkey
I learned that memset(ptr, 0, nbytes) is really fast, but is there a faster

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.