Ask Question
10 February, 09:01

What is the purpose of a constructor?

+1
Answers (1)
  1. 10 February, 10:57
    0
    The main purpose of the constructor in the computer science is to initialize the object of the class. The constructor is basically called after the allocation of the memory in the object. When the object is created, the constructor are basically used to initialize as default value.

    Constructor is also known as special type of the member function. The compiler called the constructor whenever the object has been create and the construction has similar name of the given class.

    Example:

    Class test () {

    int p, r; / / variable declaration

    public:

    / / constructor

    / / Assigning value in the constructor

    p=5;

    r=10;

    Cout<<" Constructor value/n";

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is the purpose of a constructor? ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers