Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a += b and a =+ b , also a++ and ++a?

Tags:

As I mentioned in the title,

What is the difference between a += b and a =+ b , also a++ and ++a ? I'm little confused

like image 804
Eng.Fouad Avatar asked Feb 23 '11 22:02

Eng.Fouad


People also ask

Does difference between A and B mean AB?

If A and B are two sets, then their difference is given by A - B or B - A. A - B means elements of A which are not the elements of B. Solved examples to find the difference of two sets: 1.

What is the difference between A and AB?

Definition. Type A blood has A antigens and anti-B antibodies. Type B blood has B antigens and anti-B antibodies. AB blood has AB antigens, and no antibodies and type O blood has no antigens but both anti-A and anti-B antibodies.

What does difference between A and B mean?

When someone refers to the difference between A and B, it usually does not imply there is only one difference! The difference, often with the emphasized in some way, spoken or written, means the most important difference.

How do you write the difference between A and B?

Difference of Two Sets Symbolically, we write A – B and read as “ A minus B”.


2 Answers

a += b is equivalent to a = a + b

a = +b is equivalent to a = b

a++ and ++a both increment a by 1. The difference is that a++ returns the value of a before the increment whereas ++a returns the value after the increment.

That is:

a = 10; b = ++a; //a = 11, b = 11  a = 10; b = a++; //a = 11, b = 10 
like image 100
Alex Deem Avatar answered Nov 09 '22 02:11

Alex Deem


a += b is equivalent to a = a + b

a = +b is equivalent to a = b

a++ is postfix increment and ++a is prefix increment. They do not differ when used in a standalone statement, however their evaluation result differs: a++ returns the value of a before incrementing, while ++a after. I.e.

int a = 1; int b = a++; // result: b == 1, a == 2 int c = ++a; // result: c == 3, a == 3 
like image 29
Péter Török Avatar answered Nov 09 '22 02:11

Péter Török