C++ Basic coding problem

C++ Basic coding problem

#include <iostream>
using namespace std;

class obj{
    int x;
    static int flag;
    public: 
     void getdata(int a)
     {
         x=a;
         flag++;

     }
void display(){cout<<"Enter object: "<<x<<endl;}
void getflag(){cout<<"Flag value: "<<flag<<endl;}
};
int obj::flag;

int main(){
    obj b, c, d;
    b.getdata(5);  b.display(); b.getflag();
    c.getdata(7); c.display(); c.getflag();
    d.getdata(8); d.display(); d.getflag();
    return 0;
}








Click on the above button to know the output of this code.


Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post