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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:08:55+00:00 2026-06-17T10:08:55+00:00

I understand that there is many different ways to accomplish the same thing in

  • 0

I understand that there is many different ways to accomplish the same thing in C++; however, I would like to know the differences between these methods of initializing a struct. I would also like to know what is the C++ way of doing things, as I know some of these methods are from C.

struct MyStruct
{
    int x, y, z;
};

MyStruct s1 = { 0 };  //I think this is from C but not really sure.
MyStruct s2 = { }; //I think this might be from C++
MyStruct s3 = { sizeof(MyStruct) } ; //Not sure where this comes from but I like it

When programming in C++, which should I use?

  • 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-06-17T10:08:56+00:00Added an answer on June 17, 2026 at 10:08 am

    (Assuming POD types, not the new uniform-initialization syntax)

    The three are valid initializations in C++ assuming that the struct has a first element that can be initialized from an integer. The third option sets the first member of the struct to the size of the struct, and the rest of the fields are left zero-initialized.

    The first two are equivalent in C++, although the second one is not valid C, as in C you must pass at least one value inside the braces.

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

Sidebar

Related Questions

I understand that there are many different views on the way JavaScript should be
Here is how Project Euler Problem #76 sounds like: How many different ways can
I understand that there is a setting in Sun JVM for dumping the heap
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there
I am trying to understand the co-ordinate spaces of three.js, I understand that there
Just to preface my question, I understand that there is no direct support for
Why only one overload throws this exception? Little update: I understand that there was
Is there a way to debug CoffeeScript line-by-line? I understand that it compiles into
There are things that I don't understand when it comes to linking... I'm writing
There is something that I really don't understand with the HttpListener. The code below

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.