20120113

Program in C to learn static variable in C

//========================
//Program in C to learn static variable in C
//========================
#include<iostream>
using namespace std;
class base
{
public:
        static int x;
        void modifyx()
        {
        x++;
        }
        void displayx()
        {
        cout<<"\n x="<<x;
        }
};
 int base::x=0;
class derived:public base
{
};
int main()
{
base b;
derived d;
b.modifyx();
b.displayx();
d.modifyx();
d.displayx();
return 0;
}
Previous                             Home                               Next

No comments:

Post a Comment