Ask Question

What is the purpose of a constructor?

+5
Answers (1)
  1. 17 October, 11:45
    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?
Find an answer to your question 👍 “What is the purpose of a constructor? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers