Explanation: A constructor is used in classes to initialize data members of class in order to avoid errors/segmentation faults .
Read moreWhy the constructors are used?
We use constructors to initialize the object with the default or initial state . The default values for primitives may not be what are you looking for. Another reason to use constructor is that it informs about dependencies.
Read more