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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:39:10+00:00 2026-05-20T20:39:10+00:00

I posted a question recently: Initialization of Static Class members. Now please check this

  • 0

I posted a question recently:
Initialization of Static Class members.

Now please check this code:

#include<iostream>
class A
{
    static int obj_s;
public: 
    A()
    {
        obj_s++;
        std::cout << A::obj_s << "\nObject(s) Created\n";
    }
};

int A::obj_s = 0;

int main()
{
}

Even though one has not created any object of Class A, making the member obj_s hold a value 0 – wouldn’t it need memory since its getting defined?

  • 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-20T20:39:10+00:00Added an answer on May 20, 2026 at 8:39 pm

    Obviously, it takes memory. And int A::obj_s=0 is exactly what it does: it defines the variable along with it’s memory. In fact, when we say we defined a variable X, that means we define a memory of sizeof(X), and that memory region we label as X.


    More about static members:

    A::obj_s is a static member of the class A. And static members exist without any instance. They’re not part of instances of A.

    §9.4.2/3 and 7 from the Standard,

    once the static data member has been
    defined, it exists even if no objects
    of its class have been created.

    Static data members are initialized
    and destroyed exactly like non-local
    objects (3.6.2, 3.6.3).

    Read my complete answer here:

    Do static members of a class occupy memory if no object of that class is created?

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

Sidebar

Related Questions

Recently this question was posted about the definition of what a transaction is in
I recently posted this question about codes for a gift-card-like voucher that users can
I recently posted this question on the r-help mailing list but got no answers,
I recently posted a question about Azure... is it really an OS? I understand
This question is related to the question posted here: Why isn't my custom WCF
I posted this question yesterday evening, which has led me to discover a huge
I posted this question: https://stackoverflow.com/questions/418597/java-and-net-for-php-programmer and the answers I was given didn't really help
This is in continuation with the question posted here: Finding the center of mass
Haven't seen many Geneva related questions yet, I have posted this question in the
I have a question about this question . I posted a reply there but

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.