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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:35:34+00:00 2026-06-01T14:35:34+00:00

Does int a = int(); necessarily give me a zero? How about if int

  • 0

Does int a = int(); necessarily give me a zero?

How about if int is replaced by char, double, bool or pointer type?

Where is this specified in the language standard, please?

  • 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-01T14:35:35+00:00Added an answer on June 1, 2026 at 2:35 pm

    Does int a = int(); necessarily give me a zero?

    Yes, the standard guarantees that it gives you zero.
    This is known as Value Initialization. For the type int, Value Initialization basically ends up being an Zero Initialization.

    Where is this specified in the language standard, please?

    The rules are clearly specified in the standard in section 8.5.
    I will quote the relevant ones to the Q here:

    C++03: 8.5 Initializers
    Para 7:

    An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.

    Value Initialization & Zero Initialization are defined in 8.5 Para 5 as:

    To value-initialize an object of type T means:

    — if T is a class type (clause 9) with a user-declared constructor (12.1), then the default
    constructor for T is called (and the initialization is ill-formed if T has no accessible
    default constructor);
    — if T is a non-union class type without a user-declared constructor, then every non-static
    data member and base-class component of T is value-initialized;
    — if T is an array type, then each element is value-initialized;
    — otherwise, the object is zero-initialized

    To zero-initialize an object of type T means:

    — if T is a scalar type (3.9), the object is set to the value of 0 (zero) converted to T;
    — if T is a non-union class type, each nonstatic data member and each base-class subobject
    is zero-initialized;
    — if T is a union type, the object’s first named data member is zero-initialized;
    — if T is an array type, each element is zero-initialized;
    — if T is a reference type, no initialization is performed.

    Note: The bold texts are emphasized by me.

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

Sidebar

Related Questions

Why does this code int (*g)(int); int (*h)(char); h = g; In C, give
In Guile 1.6.*, the function scm_istring2number(char *str,int strlen,int radix) does the work. However, this
I have two questions regarding this code. What does the double*** pdata and int***
For example: sizeof(char*) returns 4. As does int* , long long* , everything that
Does this code cause a memory leak: int main(){ int * a = new
Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example,
I am having an error: Error 2 'int[]' does not contain a definition for
Why does the statement (int)84 throw an exception and Convert.ToInt32(84) does not throw an
The following code does not compile: //int a = ... int? b = (int?)
typeof(int).Name Will return System.Int32 does anyone know of a way to return int

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.