The compiler provides a constructor to every class in case the provider does not offer the same. This is when the programmer provides the constructor with no specific parameters than it is called a default constructor. The code for default constructor can be displayed in the following example.
// Cpp program to illustrate the
// concept of Constructors
#include <iostream>
using namespace std;
class construct {
public:
int a, b;
// Default Constructor
construct()
{
a = 10;
b = 20;
}
};
int main()
{
// Default constructor called automatically
// when the object is created
construct c;
cout << "a: " << c.a << endl
<< "b: " << c.b;
return 1;
}
Posted Date:- 2021-08-24 05:18:12
Which is the best C++ compiler?
Which operator cannot be overloaded in C++ ?
What differences separate structure from a class in C++?
Can we provide one default constructor for our class?
What is the default constructor?
Is it possible for a C++ program to be compiled without the main() function?
What Is A Unnitialised Pointer?
What Is The Disadvantage Of Using A Macro?
What Do You Mean By Global Variables?
What are logical error and how does it differ from syntax error?
How to run C++ program in cmd?
Explain the significance of vTable and vptr in C++ and how the compiler deals with them
Can we declare variable anywhare in c ?
Control Statements or Control Flow ?
How to download turbo C++ for windows 10?
What is operator overloading in C++?
Can we use a continue statement without using a loop?
What is the difference between the text file and a binary file?
What is the importance of an algorithm in C programming?
Can we have a recursive inline function in C++?
What is the function of the keyword “Volatile�
Briefly explain the concept of Inheritance in C++.
Can we call C++ OOPS? and Why?
What are the User-defined Functions?
What are the Pre-defined Functions?
What are the differences between references and pointers?
What are the differences between C and C++?
What Are Structures And Unions?
Types of errors in c?
Errors in c programming are divid