161. Write a program to initialize member variable by using constructor?

#include<iostream.h>
#include<conio.h>
class demo
{
                int x;
public:
                demo()
                                {
                                x=20;
                                }
                void display()
                                {
                                cout<<"X = "<<x<<endl;
                                }
};
void main()
                {
                demo d;
                clrscr();
                d.display();
                getch();
}

161

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: