Characteristic of constructor: –

It has same name as of its class name. It does not have return type so it does not return any value. It has three types – default, parameterize, copy constructor. It is use to allocate the memory to the object. It can be overloaded (We can have n number of constructors with in same... Continue Reading →

Advertisements

Constructor: –

Constructor: - It is a special member function which is use to allocate the memory for the object. Whenever the object will be created or declare, immediately the constructor will be called. If we have not taken any constructor then compiler will automatically create default constructor with empty body inside public section of class. Syntax:... Continue Reading →

Default constructor: –

Default constructor: - When constructor has zero parameter inside its parentheses then constructor is called as default constructor. Syntax: -                 Class_Name()                                 {                                 } Parameterized constructor: - When the constructor has one or more than one parameter inside its parenthesis then the constructor is called as parameterized constructor. Syntax: -                 Class_Name(Argument 1,... Continue Reading →

174. Write a program to demonstrate recursive constructor call?

#include<iostream.h> #include<conio.h> int c=0; class demo { private:                 int x;                 demo()                                 {                                 if(c<=3)                                                 {                                                 cout<<"Private Default Constructor Is Executed"<<endl;                                                 x=10-c;                                                 cout<<"C = "<<c<<endl;                                                 cout<<"X = "<<x<<endl;                                                 ++c;                                                 demo();               //Recursive Constructor Call                                                 }                                 } public:                 demo *func()                                 {                                 return (new... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: