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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:30:07+00:00 2026-06-09T18:30:07+00:00

std::array<int,4> myInts; std::array<bool,2> myBools; Can the elements of myInts and myBools be assumed to

  • 0
std::array<int,4> myInts;
std::array<bool,2> myBools;

Can the elements of myInts and myBools be assumed to be false and 0, or should I fill the arrays manually?

  • 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-09T18:30:09+00:00Added an answer on June 9, 2026 at 6:30 pm

    The elements will be set to random values, but you can make sure to value initialize them like this:

    std::array<int,4> myInts{}; // all zeroes
    std::array<bool,2> myBools{}; // all false
    

    So the elements do not have to be reset, they can be initialized to certain values. You can also initialize elements to different values:

    std::array<int,4> myInts{1,2,33,44};
    std::array<bool,2> myBools{true, false};
    

    If you have less elements than the size of the array in the initializer list, then the missing ones get zero initialized:

    std::array<int,4> myInts{1,2}; // array contains 1,2,0,0
    

    Note The standard specifies that std::array is an aggregate, and has some example code where it shows it implemented as having an array data member. It claims this is just to emphasize that the type is an aggregate, but if this implementation is used (and GCC uses it) then you would need an extra set of braces because you are initializing the array inside the std::array:

    std::array<int,4> myInts{ {1,2,33,44} };
    

    On the other hand, this case qualifies for brace elision, so the extra set of braces is not mandatory.

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

Sidebar

Related Questions

I can sort a int* array using stl, plain and simple like std::sort(myarray, myarray
I have problem i need to convert from my Array structure to std::vector<int> ...
#include <iostream> #include <iomanip> using namespace std; int main() { char array[10]; for(int i
How can I use std::shared_ptr for array of double? Additionally what are advantages/disadvantages of
When should I use std::string and when should I use char* to manage arrays
after reading inputs to an array: std::vector<unsigned char *> inputs(elements); the inputs is a
How do smart pointers handle arrays? For example, void function() { std::unique_ptr<int> my_array(new int[5]);
Code: std::vector<int> x{1,2,3,4}; std::array<int, 4> y{{1,2,3,4}}; Why do I need double curly braces for
I have some C+ arrays that I have built as follows: std:array<const char *,
Is the data in std::array<std::array<T,N>, M> guaranteed to be contiguous? For example: #include <array>

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.