TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 22 June 2020

Constructor With Default Argument In C++| Constructor With Default Argument In C++ Example| Constructor With Default Argument In C++ Syntax| Constructor With Default Argument In C++ Program | Constructor With Default Argument In C++ In Hindi

Constructor With Default Argument In C++

A default argument is a value provided in a function declaration that is automatically assigned by the compiler if the caller of the function doesn’t provide a value for the argument with a default value.

image of constructor with default argument in c++

Fig: Constructor With Default Argument In C++

Syntax:

class class name

{

Public:

Classname(datatype variablename=value);

----

----

};


Program:

#include<iostream.h>

#include<conio.h>

class BCA

{

int a,b;

public:

BCA(int x,int y=30);

void display();

};

BCA::BCA(int x,int y)

{

a=x;

 b=y;

}

void BCA:: display()

{

cout<<”a=”<<a;

cout<<”b=”<<b;

}

void main()

{

BCA a1(10);

a1.display();

getch();

}


Output:

a=10 b=30


No comments:

Post a Comment