Parameterized constructors in C++ are constructors that accept arguments to initialize objects with specific values during object creation. They help create objects with different initial values instead of using default initialization.
In this chapter, you will learn about parameterized constructors in C++, their syntax, declaration, definition, and how they are used to initialize objects with custom values.
In the C++ programming language, a parameterized constructor is a constructor that can take one or more arguments. These constructors are mainly used to pass values for initializing an object during its creation. They allow the object to be initialized with specific values instead of depending on default initialization. Inside the constructor body, the parameters can be used to initialize the data members of the object.

A parameterized constructor is declared and defined inside or outside the class using parameters that are passed during object creation.
The following syntax is used to declare and define a parameterized constructor in C++:
In this syntax,
Consider the following example demonstrating the use of a parameterized constructor.
Output:
Employee Name: Jhonson, Age: 21, Salary: 45000 Employee Name: Michael, Age: 19, Salary: 53000
Explanation:
In this example, we have taken an Employee class that has data members name, age, and salary. We initialize these data members directly using the constructor during object creation. After that, we initialize two employees, emp1 and emp2, with specific values, and the show() function displays their details.
A parameterized constructor can also be used together with a destructor in a class. The constructor is used to initialize the object with specific values during object creation, while the destructor is automatically called when the object is destroyed. This helps in understanding the complete lifecycle of an object.
Consider the following example demonstrating the use of a parameterized constructor with a destructor.
Output:
The values for t1.x is: 20 The values for t2.x is: 15 After destructing the objects which are having the value of x is as follows: 15 After destructing the objects which are having the value of x is as follows: 20
Explanation:
In this example, the class ParamCode uses a parameterized constructor to initialize the variable x when the objects t1 and t2 are created with the values 20 and 15. After displaying the values of x, the destructor is automatically called when the program ends, and it prints the value of x for each object as the objects are destroyed.
In the C++ programming language, the parameterized constructor can also have a default constructor. It allows us to define default values for the arguments of parameterized constructors. If we don't pass an argument during the object creation, the constructor can automatically utilize the specified default value. It helps to reduce the requirement for multiple overhead constructors, which makes the code simpler, effective, and flexible.
It has the following syntax:
In this syntax,
Let us take an example to illustrate the default arguments with a parameterized constructor in C++.
Output:
The resultant output is : 7 2
Explanation:
In this example, we have taken a class Tpoint that has a constructor. After that, it takes an integer parameter p, which defaults to 2 if no value is provided. When obj1 is created with 7, its value is set to 7, while obj2 is created without an argument, so it takes the default value 2. Finally, it displays the output in the console.
In the C++ programming language, the member initializer lists offer a method to initialize class data members directly before the execution of the constructor body. We need to use the colon (:) to initialize the value during object creation, which is followed by the initialization list.
It has the following syntax:
Let us take an example to illustrate the member initializer lists in a parameterized constructor in C++.
Output:
x = 15, y = 30 x = 8, y = 20
Explanation:
In this example, we have taken the class Tpoint that has two private variables, x and y, which are directly initialized using the initializer list when objects are created. After that, we initialize two objects t1 and t2 with values (15, 30) and (8, 20). Finally, the show() function prints these values.
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India