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

  • Home
  • SEARCH
  • 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 168679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:29:45+00:00 2026-05-11T12:29:45+00:00

I originally wrote some code like this: class Foo { public: Foo() : m_buffer()

  • 0

I originally wrote some code like this:

class Foo { public:   Foo() : m_buffer()     {}  private:   char   m_buffer[1024]; }; 

Someone who is smarter than me said that having the m_buffer() initializer would zero out the memory. My intention was to leave the memory uninitialized. I didn’t have time to discuss it further, but it piqued my curiosity.

Previously, I had thought it was wise to always list each member in the initializer list.

Could someone please describe this behavior further?

1) Why does the empty-paren initializer fill in memory?

2) Does it only hold for POD datatypes? I heard that it was so, but don’t have the standard handy.

Thanks

  • 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. 2026-05-11T12:29:46+00:00Added an answer on May 11, 2026 at 12:29 pm

    If you have a member initialized like that, it will be value-initialized. That is also true for PODs. For a struct, every member is value-initialized that way, and for an array, every element of it is value-initialized.

    Value-initialization for a scalar type like pointer or integer you will have it inialized to 0 converted to the right type. So you will get null pointers or false or whatever type you have concretely.

    Note that the rule changed subtly from C++98 to C++03 (what we have right now), which can have surprising effects. C++98 didn’t have that value-initialization. It said default initialization happens, which for a non-POD type always meant it’s default constructor invokes. But value-initialization in C++03 has special meaning if there is no user-declared constructor: Every element is value-initialized then.

    Here is the difference:

    struct A { int c; ~A() { } }; // non-POD, but no user declared ctor struct B { A a; B():a(){ } } b; 

    Now, in C++03, you will be guaranteed that b.a.c is zero. While in C++98, b.a.c will have some indeterminated value.

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer -//folderName/folderName/folderName/*.class //workspaceName/folderName/folderName/*.class If this line is in the "View" area… May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer ArgoUML has been my friend for many years when it… May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer UART is the abbreviation of Universal Asynchronous Receiver Transmitter, the… May 11, 2026 at 7:52 pm

Related Questions

Whenever I try to write graphical programs (whether a game or really any GUI
I want to convert function object to function. I wrote this code, but it
I wrote a quick and dirty wrapper around svn.exe to retrieve some content and
I've joined a team that works on a product. This product has been around

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.