What is a constructor in c++ with example?
Answer / Pranaw Kumara
In C++, a constructor is a special function that's used to initialize objects. The constructor has the same name as its class and has no return type (except for the bool constructor). Here's an example:n```cppnclass Rectangle {n private:n int width;n int height;nn public:n Rectangle(int width, int height) : width(width), height(height) {}n // ... other methods and members heren};nnint main() {n Rectangle rect(5, 10); // Calling constructor to create a new objectn return 0;n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);
Is it possible for a member function to use delete this?
What are all predefined data types in c++?
What is c++ course?
Why namespace is used in c++?
What is microsoft c++ redistributable 2013?
C++ program output? Explain output of this program. #include <iostream> using std::cout; using std::cin; int main() { cout<<cout<<' '; cout<<cin; return 0; } It prints some address in hexadecimal. what is it?
What is the use of function pointer?
Is atoi safe?
Can notepad ++ run c++?
What is the difference between std::vector and std::list
What is array in c++ pdf?