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 7 September 2020

Increment (++) And Decrement (--)Operator Overloading In C++| Increment (++) And Decrement (--)Operator Overloading In C++ In Hindi

 

Increment (++) And Decrement (--)Operator  Overloading  In  C++

Operator overloading is a feature in object-oriented programming which allows a programmer to redefine a built-in operator to work with user-defined data types.

Overloading the increment operator

The operator symbol for both prefix(++i) and postfix(i++) are the same. Hence, we need two different function definitions to distinguish between them.


Overloading the decrement operator

 Overload the decrement operator (--) decrement and here is program

image of Increment (++) And Decrement (--)Operator  Overloading  In  C++
Fig: Increment (++) And Decrement (--)Operator  Overloading  In  C++


 

Program:

 

#include<iostream.h>

#include<conio.h>

class num

{

private:

int n;

public:

void getnum(int x)

{

n=x;

}

void dispnum(void)

{

cout<<”value of n is: “<<n;

}

void operator++(void)

{

n=++n;

}

Void operator—(void)

{

n=--n;

}

};

int main()

{

num a1;

a1.getnum(10);

++a1;

cout<<”after increment-“;

a1.dispnum();

cout<<endl;

--a1;

cout<<”after decrement-“;

a1.dispnum();

cout<<endl;

return 0;

}

 

Output:


After increment- value of n is:11

After decrement-value of n is:10

 

 

 

No comments:

Post a Comment