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 812809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:15:39+00:00 2026-05-15T01:15:39+00:00

gcc 4.4.4 C89 I am just wondering what most C programmers do when they

  • 0

gcc 4.4.4 C89

I am just wondering what most C programmers do when they want to zero out memory.

For example, I have a buffer of 1024 bytes. Sometimes I do this:

char buffer[1024] = {0};

Which will zero all bytes.

However, should I declare it like this and use memset?

char buffer[1024];
.
.
memset(buffer, 0, sizeof(buffer));

Is there any real reason you have to zero the memory? What is the worst that can happen by not doing it?

  • 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-15T01:15:39+00:00Added an answer on May 15, 2026 at 1:15 am

    The worst that can happen? You end up (unwittingly) with a string that is not NULL terminated, or an integer that inherits whatever happened to be to the right of it after you printed to part of the buffer. Yet, unterminated strings can happen other ways, too, even if you initialized the buffer.

    Edit (from comments) The end of the world is also a remote possibility, depending on what you are doing.

    Either is undesirable. However, unless completely eschewing dynamically allocated memory, most statically allocated buffers are typically rather small, which makes memset() relatively cheap. In fact, much cheaper than most calls to calloc() for dynamic blocks, which tend to be bigger than ~2k.

    c99 contains language regarding default initialization values, I can’t, however, seem to make gcc -std=c99 agree with that, using any kind of storage.

    Still, with a lot of older compilers (and compilers that aren’t quite c99) still in use, I prefer to just use memset()

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

Sidebar

Related Questions

gcc 4.4.4 c89 I am just wondering is it worth passing a const into
gcc 4.4.4 c89 I am just wondering is there any standard that should be
gcc 4.4.3 c89 pthreads I use valgrind for checking memory errors. I am just
gcc 4.4.3 c89 I am trying to display the address. Basically, I just want
gcc 4.5.1 c89 I am maintaining someone's code. And they have got things really
gcc 4.4.2 c89 I have this code snippet that I have to repeat in
gcc 4.4.1 I am just wondering which standard is better and more portable? I
I am using gcc 4.4.2 on linux I am just wondering does gcc automatically
gcc 4.4.2 c89 I am have been re-engineering some one else's source code. In
gcc 4.4.2 c89 I have the following enum: enum drop_options_e { drop_ssm, drop_snm, drop_ssb

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.