Why constructor in c++

(q) Why constructor ? Ans: Goal of c++ is to create such type of class which is very similar to basic data type like int char,float etc. It is possible in basic data type like int,char etc we can initialize the data type at the time of creation . Example: #include #include int main() { int a=6; //intialization at the time char b='v'; // of creation clrscr(); cout< #include class country { char *name; long int population; public: void getdata() { Name=”USA”; Population=700000000; } void display() { cout< #include class country { char *name; long int population; public: country() { name="India"; population=1000000000; } void display() { cout<
Post a Comment