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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:50:15+00:00 2026-05-28T13:50:15+00:00

After writing: std::pair<int, int> x; Am I guaranteed that x.first and x.second are both

  • 0

After writing:

std::pair<int, int> x;

Am I guaranteed that x.first and x.second are both zero? Or could they have any value?

The reason why I care is because I’m trying to determine whether a map whose values are pointers is guaranteed to return NULL if I access an element that’s not in the map. I.e., if I do:

std::map<int, void*> my_map;
std::cout << int(my_map[5]) << std::endl;

then am I guaranteed to get zero (NULL)? Or is the behavior undefined?

  • 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-28T13:50:17+00:00Added an answer on May 28, 2026 at 1:50 pm

    Yes, that guarantee holds true. Quoting the C++11 standard, §20.3.2/2-3:

            constexpr pair();

    2 Requires: is_default_constructible<first_type>::value is true and is_default_constructible<second_type>::value is true.
    3 Effects: Value-initializes first and second.

    And §8.5/7:

    To value-initialize an object of type T means:

    • if T is a (possibly cv-qualified) class type with a user-provided constructor, 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 (possibly cv-qualified) non-union class type without a user-provided constructor, then the object is zero-initialized and, if T‘s implicitly-declared default constructor is non-trivial, that constructor is called.
    • if T is an array type, then each element is value-initialized;
    • otherwise, the object is zero-initialized.

    And lastly, §8.5/5:

    To zero-initialize an object or reference of type T means:

    • if T is a scalar type, the object is set to the value 0 (zero), taken as an integral constant expression, converted to T;
    • if T is a (possibly cv-qualified) non-union class type, each non-static data member and each base-class subobject is zero-initialized and padding is initialized to zero bits;
    • if T is a (possibly cv-qualified) union type, the object’s first non-static named data member is zero-initialized and padding is initialized to zero bits;
    • if T is an array type, each element is zero-initialized;
    • if T is a reference type, no initialization is performed.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I'm writing an application that displays Google Map right after the login screen. The
I'm writing a tic tac toe program that plays throuh the terminal/console After Player
I was writing a script that kept giving me errors. After tracking it down
I have the following code: void Foo() { static std::vector<int>(3); // Vector object is
I have a std::map that is used by multiple threads to store data. The
Latelly I've been working with multi-thread coding, after a while writing I realized that
I'm writing a (C++) application that utilizes a single dialog box. After setting up
After writing the code below: #include <iostream> using namespace std; typedef struct Node {
I am using JQuery to execute an operation within a web service. After writing

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.