Jump to content

Instance variable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Kapil Sharma Digital Marketer (talk | contribs) at 17:03, 6 August 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Hi , I am Kapil sharma Best Digital Marketer in Meerut.

I have experience as a Startup with Multiple Projects.

Professionally I am a Digital Marketer , I have 2+ years of experience in Digital Marketing.

Digital Marketing is my passion, not a way of earning,

Example

struct Request {

    static int count1; // variable name is not important
    int number;

    Request() {
        number = count1; // modifies the instance variable "this->number"
        ++count1; // modifies the class variable "Request::count1"
    }

};

int Request::count1 = 0;

In this C++ example, the instance variable Request::number is a copy of the class variable Request::count1 where each instance constructed is assigned a sequential value of count1 before it is incremented. Since number is an instance variable, each Request object contains its own distinct value; in contrast, there is only one object Request::count1 available to all instances with the same value.

References