answersLogoWhite

0


Best Answer

The '+=' operator behaves like a pre increment operator.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is x plus equals y is post increment or pre increment?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the meaning of plus plus in c?

++a (plus plus a) is pre-incrementing operator to aa=10;printf("%d",++a); /* it will print 11 as ++a increment first a by 1 then prints it */printf("%d",a++); /*it will printf 10 as it is post _ increment operator , it prints the value a first then increment it by 1 */


How can you differentiate overloading of pre-fix and post-fix increment operator?

The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


What are applications of pre-increment and post-increment operators why these operators behaviour are made like this is there any reason for such behaviour?

All operators must return a value, and it is this return value (the evaluation of the operation) that differentiates the pre-increment and post-increment operators. If the return value is of no concern, then the pre-increment operator is the preferred version, particularly when working with objects. This is because the post-increment operator's implementation will generally make a copy of the original object which it will return after incrementing the original object. If the return value is of no concern, then making a copy adds an expensive overhead (this doesn't apply to primitive data types since CPU optimisation can pre-empt the return value without requiring a copy to be made). Applications for post-increment and pre-increment are many and varied, but ultimately the goal is to increment the value. Whether you use post-increment or pre-increment is largely down to whether you need to use the return value or not, and whether you need to use the original value or the incremented value. Although the same thing can be achieved with longhand code, it is more efficient to use the appropriate post-increment or pre-increment operators. For instance: int x=1; int y=x; ++x; Can be implemented more efficiently with: int x=1; int y= x++; Whereas: int x=1; ++x; int y=x; Can be implemented more efficiently with: int x=1; int y= ++x; Use caution when pre-incrementing the same value in a compound statement. For example: int x=0; int y= ++x * ++x; The expected result is 2, but the actual result is 4. This is because both expressions (++x) return the same value: a reference to x. And since x is incremented twice, the expression evaluates to 2*2, not 1*2. To get the expected result of 2, each operation must be evaluated separately: int x=0; int y= ++x; y*= ++x;


What is increment and decrement operators?

increment operator increments the variable by 1 at a time and decrement operator decrements by 1 in this we have two types increments pre_increment and post increment. In pre_increment the original value is incremented by 1 and assign the new value n=10 i=++n then i =11 In post increment the original value is assigned and after it increments value by 1. n=10 i=n++ then i=10 example: k=5 i=k++ + ++k i=? ans: in first k++ value is 5 second ++k value is 7 i=5+7=12


What is the difference between post and pre increment unary operators in c with example?

They both increment the variable. But the value returned by the pre-increment operator is the value of the variable after it has been incremented, while the value returned by the post-increment operator is the value before it has been incremented.For example:int a = 1;int b = ++a;// Now a is 2 and b is also 2.int a = 1;int b = a++;// Now a is 2 but b is 1.

Related questions

How different is pre and post increment in c plus plus from pre and post increment in C programming?

The pre and post increment (and decrement) operator is the same in C++ as it is in C.


What is the meaning of plus plus in c?

++a (plus plus a) is pre-incrementing operator to aa=10;printf("%d",++a); /* it will print 11 as ++a increment first a by 1 then prints it */printf("%d",a++); /*it will printf 10 as it is post _ increment operator , it prints the value a first then increment it by 1 */


Why c plus plus name was given?

In C, the ++ operator means to increment the object associated with it. If you said xyz++; for instance, you would increment xyz. (There are pre-increment and post-increment forms, but that is out of scope for this question.) When the C language was enhanced, the new language was called C++, implying that C++ was the "next", or "incremented", version of C.


What is the use of using pre increment operator?

int a, b; b = 5; /* post-increment operator */ a = b++; /* a is now 5, and b is now 6. */ /* pre-increment operator */ a = ++b; /* a and b are now both 7 */


How can you differentiate overloading of pre-fix and post-fix increment operator?

The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


How the predecrementer and postdecrementer are taken care of while declaring operator overloading?

When you overload the -- and ++ operators in C++, if you want the pre version, aka --var, simply declare the function without an argument; whereas if you want the post version, aka var--, simply declare the function with an argument of type int. class abc { public: abc& operator++(); // pre-increment form abc& operator++(int); // post-increment form ... }; abc::operator++() { ... pre increment stuff return *this; } abc::operator++(int) { ... post increment stuff return *this; }


What is the declaration of overloaded pre-increment operator implemented as member function?

The pre-increment operator accepts no parameters and returns the same object (by reference) after incrementing. The post-increment operator accepts an unused (dummy) integer parameter and returns a copy of the object (by value) that is made immediately prior to incrementing the object. Note that it is good practice to always use the pre-increment operator even if a post-increment operator exists. The only time you should ever use a post-increment is when you actually store the return value. If you don't store the return value then you will end up making an unnecessary copy, which is highly inefficient. With primitive data types that are less than or equal in length to a pointer this isn't a major issue, but it's good practice nonetheless. If you do it for primitives then you're far more likely to remember to do it for class instances as well. The following example emulates an integer type with pre-increment and post-increment operators implemented: class Simple { public: // Construction: Simple(int data = 0):m_data(data){} Simple(const Simple& simple):m_data(simple.m_data){} public: // Assignment: Simple& operator= (const Simple& simple) { m_data = simple.m_data; return( *this ); } // pre-increment: Simple& operator++ () { // no parameters! ++m_data; // increment this object return( *this ); } // return a reference to this object // post-increment: Simple operator++(int) { // int parameter (not used)! Simple copy( *this ); // call the copy constructor ++m_data; // increment this object return( copy ); } // return the copy (by value) private: int m_data; };


What are applications of pre-increment and post-increment operators why these operators behaviour are made like this is there any reason for such behaviour?

All operators must return a value, and it is this return value (the evaluation of the operation) that differentiates the pre-increment and post-increment operators. If the return value is of no concern, then the pre-increment operator is the preferred version, particularly when working with objects. This is because the post-increment operator's implementation will generally make a copy of the original object which it will return after incrementing the original object. If the return value is of no concern, then making a copy adds an expensive overhead (this doesn't apply to primitive data types since CPU optimisation can pre-empt the return value without requiring a copy to be made). Applications for post-increment and pre-increment are many and varied, but ultimately the goal is to increment the value. Whether you use post-increment or pre-increment is largely down to whether you need to use the return value or not, and whether you need to use the original value or the incremented value. Although the same thing can be achieved with longhand code, it is more efficient to use the appropriate post-increment or pre-increment operators. For instance: int x=1; int y=x; ++x; Can be implemented more efficiently with: int x=1; int y= x++; Whereas: int x=1; ++x; int y=x; Can be implemented more efficiently with: int x=1; int y= ++x; Use caution when pre-incrementing the same value in a compound statement. For example: int x=0; int y= ++x * ++x; The expected result is 2, but the actual result is 4. This is because both expressions (++x) return the same value: a reference to x. And since x is incremented twice, the expression evaluates to 2*2, not 1*2. To get the expected result of 2, each operation must be evaluated separately: int x=0; int y= ++x; y*= ++x;


Program in java to illustrate the pre increment and post increment?

An example might help:int a, b;a= 2;b= a++;/* now a=3, b=2 */a= 2;b= ++a;/* now a=3, b=3 */Read more: What_is_difference_between_pre_increment_and_post_increment


What is increment and decrement operators?

increment operator increments the variable by 1 at a time and decrement operator decrements by 1 in this we have two types increments pre_increment and post increment. In pre_increment the original value is incremented by 1 and assign the new value n=10 i=++n then i =11 In post increment the original value is assigned and after it increments value by 1. n=10 i=n++ then i=10 example: k=5 i=k++ + ++k i=? ans: in first k++ value is 5 second ++k value is 7 i=5+7=12


What is the difference between post and pre increment unary operators in c with example?

They both increment the variable. But the value returned by the pre-increment operator is the value of the variable after it has been incremented, while the value returned by the post-increment operator is the value before it has been incremented.For example:int a = 1;int b = ++a;// Now a is 2 and b is also 2.int a = 1;int b = a++;// Now a is 2 but b is 1.


What is post and pre issue capital?

Post and pre issue capital is one thing. It is capital and post money.