How a*=2 work

From http://www.cplusplus.com/doc/tutorial/functions/


1
2
3
4
5
6
void duplicate (int& a, int& b, int& c)
{
  a*=2;
  b*=2;
  c*=2;
}


How a*=2 actually work ??
a *= 2 ; is equivalent to a = a * 2 ;

a += 7 ; is equivalent to a = a + 7 ;

a -= b ; is equivalent to a = a - b ;

Except that in a *= 2 ;, a is evaluated only one; in a = a * 2 ;, a is evaluated twice. (You can safely ignore this nicety for the present; it will become clear once you become familiar with the concept of an expression in C++.)
Last edited on
Many thanks...
Topic archived. No new replies allowed.