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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:32:23+00:00 2026-06-09T05:32:23+00:00

As much as i know, constant class members must be initialized before the constructor

  • 0

As much as i know, constant class members must be initialized before the constructor runs, but since they cannot be initialized in the class body (as it is just a prototype), therefore we need to initialize it inside initializer list. My question is when does memory gets allocated to a constant variable, and what is the order of execution?

class constant
{
    const int a;
    public:
    constant(int k):a(k)
    {   
        cout<<"a is "<<a<<endl;
    }   
};

int main()
{
    constant cl(5);
    return 0;
} 

EDIT: Is it true that constant variables need to be initialized at the point where they are allocated memory?

  • 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-09T05:32:25+00:00Added an answer on June 9, 2026 at 5:32 am

    I think you have the wrong idea about const. Think less of it as related to implementation details (like memory), or runtime, and more there as a means to help the programmer and for the compiler.

    It doesn’t matter when the memory gets allocated (although it’s before you construct the object, before entering the initializer list – not specified by the standard), what matters is you can only initialize the variable in the intializer list (pre C++11) or even the class definition for const integral types.

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

Sidebar

Related Questions

I don't know much about the MS world, but now it happens to be
I don't know much about poking at servers, etc, but in light of the
I know that lookup time is constant for ETS tables. But I also heard
I am sorry for my newbie question, but I do not know much about
I don't know much about web development, so probably this question will sound exceptionally
I don't know much about multimedia development and am having some trouble comparing Silverlight
I don't know much css or html, so I have a question about taking
i don't know much about IIS, except it's a web server (just like apache)
I really don't know much about Apache, I followed some tutorials and installed the
So I don't know much about SQL or VBScript, much less putting the two

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.