Ask Question
4 May, 20:22

What is the purpose of a constructor?

+4
Answers (1)
  1. 4 May, 20:58
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers