TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday 4 June 2020

Static Data Member In C++ | Static Data Member In C++ With Example | Use Of Static Data Member In C++ | Static Data Member In C++ In Hindi

Static Data Member In C++

We can define class members static using static keyword. When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member.

A static member is shared by all objects of the class. All static data is initialized to zero when the first object is created, if no other initialization is present.


image of Static Data Member In C++

Fig: Static Data Member In C++ 


Program:


#include<iostream.h>

#include<conio.h>

class MCA

{

private:

static int count;

public :

void getdata(int);

void putdata();

};

void MCA::getdata(int x)

{

count =x;

count x++;

}

void MCA :: putdata()

{

cout<< “count=”count;

}

int MCA::count

{

void main()

{

MCA a1;

a1.putdata();

a1.putdata();

a1.getdata(20);

a1.getdata(30);

a1.putdata();

a1.putdata();

getch();

}


Output:


Count=0 count=0

Count=30 count =30


No comments:

Post a Comment