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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:18:32+00:00 2026-05-26T05:18:32+00:00

This is a good old C array: int a[10]; And this is a good

  • 0

This is a good old C array:

int a[10];

And this is a good old C array that is const:

const int b[10];

In C++, there seem to be two ways to define std::arrays that are const:

std::array<const int, 10> c;
const std::array<int, 10> d;

Are these two definitions equivalent? If so, what is the idiomatic one? If not, what are the differences?

  • 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-26T05:18:33+00:00Added an answer on May 26, 2026 at 5:18 am

    Well, the original const int b[10]; is only useful when you can initialize the array, so both of the std::array examples don’t work in practice.

    1:

    std::array<const int, 10> c;
    

    This is the closest to const int c[10];. The problem is there will be no default constructor for it, and because the elements are not mutable, it’s worthless to use this. You must provide some initialization for it in the constructor. As-is, it will give a compiler error because the default constructor did not initialize the elements.

    This code means that c is mutable, but the elements themselves are not. In practice, however, there are no mutations on c that don’t affect the elements.

    2:

    const std::array<int, 10> d;
    

    This means d is not mutable, but the elements are of mutable type int. Because const will propagate to the members, it means the elements are still not mutable by the caller. Similar to the above example, you will need to initialize d because it’s const.

    In practice, they will both behave similarly with respect to mutability, because mutable operations on array always touch the elements.

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

Sidebar

Related Questions

I remember using values array on good old mx:HSlider, is there any workaround for
I know there are emulators, but is this good enough? If someone is serious
Following this question: Good crash reporting library in c# Is there any library like
I realised this might be relatively niche, but maybe that's why this is good
I'm not sure if I can accomplish this with good old HTML, or if
This has to be simple, at least it was in good old .Net where
Not sure where else to ask this, so I figured I'd give good old
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
This is good: import string string.capwords("proper name") Out: 'Proper Name' This is not so
Is this a good method to save to all index in a variable and

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.