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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:27:09+00:00 2026-05-16T06:27:09+00:00

declaring a struct Table: struct Tables { int i; int vi[10]; Table t1; Table

  • 0

declaring a struct Table:

struct Tables {
       int i;
       int vi[10];
       Table t1;
       Table vt[10];
};

Tables tt;

assuming that a user-deault contructor is defined for Table.

here tt.t1 will be initialized using the default contructor for Table, as well as each element in tt.vt.

On the other hand tt.i and tt.vi are not initialized because those objects are not of a class type.

so we remain with a semi-initialized object tt.

if I understood well – if tt.i or tt.vi won’t be explicitly initialized i the code, after creating tt, an error will be thrown if we try to read a value from them?

2) can someone explain it to me, why cpp designers didn’t want to simply initialize the built-in types int and int[] to zero?

  • 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-16T06:27:10+00:00Added an answer on May 16, 2026 at 6:27 am

    No, no error will be thrown. You will have a mild case of undefined behaviour. However, as integers don’t have trap values, there is no way the behaviour can be detected.

    Note that the C++ language itself throws exceptions only very, very rarely – about the only times I can think of where it does it is when performing an invalid cast to a reference via dynamic_cast, and when new fails to allocate. Of course the Standard Library may throw in a number of error conditions.

    As to why C++ works that way (and C too), well initialisation takes time, and if it is not needed that is time wasted. For example, if you were going to read user input immediately into those variables, there is little point in initialising them before you do so.

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

Sidebar

Related Questions

When declaring any primitive type data like int or double they get initialized to
Declaring a struct with typedef typedef struct some_struct { int someValue; } *pSomeStruct; and
In theory it seems that books sugest declaring ADT in C as: struct some_structure;
Is declaring an attribute of a table as UNIQUE equivalent to declaring it as
When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is
hi all i am declaring id and class when creating table dynamically as below
I am declaring a SQL string that looks something similar to the following: string
I heard somewhere that declaring an Index on a date column is bad for
Is Apple declaring method [CIImage initWithImage:(CIImage*)] that I'm not aware of? The only method
I have the following types: struct X { int x; X( int val )

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.