0% found this document useful (0 votes)
22 views1 page

P Constructor

Uploaded by

ManmathNath Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

P Constructor

Uploaded by

ManmathNath Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Example :

class Cube
{
int side;
public:
Cube()
{
side=10;
}
};
int main()
{
Cube c;
cout << c.side;
}

Output : 10

Parameterized Constructor
These are the constructors with parameter. Using this Constructor you can provide different
values to data members of different objects, by passing the appropriate values as argument.

Example-1 :
#include<iostream>
using namespace std;

class A
{
int a;

public:
A(int b):a(b)
{

}
void disp()
{
cout<<a;
}
};

int main()
{
A ob(10);
ob.disp();
return 0;
}

You might also like