assignment and its variations
o lvalue and rvalue (lcoation vs. value)
o var += 2 ➔
return value vs side affect
o in assignment, in << whats the fiference?
pre and post increment and decrement
o return vs side effect
value is variable on LHS. r value is expression on right hand side o .
-lvalue always represents a memory location.
-rvalue is result of an expression evaluation. you have a lvalue=rvalue whatever expression is evaluates as a
VALUE is assigned to the location represented by the lvalue.
int main()
{
long my_long = 10; KNOW is a declaration because long is a type, = sign is context of an expression,
long a_long = 20;
mylong = mylong + along; not a declaration of type becayse doesnt start with a type. yeild rvalue 3o, assign to
location of mylong. on rhs is a value, on lhs is a location.
mylong = my long
myong on rhs is a rvalue, on lhs is a left value
cout << "*assignment returns a value!" <<endl; when we do the
cout << "mylong = 15 returns:" << (mylong = 15) << endl;
int my_int, an_int;
cout << endl << "*** Chained assignment expressions ***" << endl;
cout << "Assignment is right to left: :"<<(an_int = my_int = 5)<< endl;
cout << "my_int: " << my_int << endl;
cout << "an_int: " << an_int << endl << endl;
cout << "*** Compound assignment expressions ***" << endl;
my_int = 15; my_int += 2;
cout << "Statements: my_int = 15 followed by my_int += 2;" << endl;
cout << "my_int: " << my_int << endl << endl;
my_int = 15; my_int -= 2;
cout << "Statements: my_int = 15 followed by my_int -= 2;" << endl;
cout << "my_int: " << my_int << endl << endl;
my_int = 15; my_int *= 2;
cout << "Statements: my_int = 15 followed by my_int *= 2;" << endl;
cout << "my_int: " << my_int << endl << endl;
my_int = 15; my_int /= 2;
cout << "Statements: my_int = 15 followed by my_int /= 2;" << endl;
cout << "my_int: " << my_int << endl << endl;
cout << "*** Increment expressions ***" << endl;
my_int = 20;
cout << "my_int starts at 20"<<endl;
cout << "Value of ++my_int: " << ++my_int << endl;
cout << "Value of my_int:
" << my_int
<< endl;
cout << "Value of my_int++: " << my_int++ << endl;
cout << "Value of my_int:
" << my_int
<< endl << endl;
cout << "*** Decrement expressions ***" << endl << endl;
my_int = 30;
cout << "my_int starts at 30"<<endl;
cout << "Value of --my_int: " << --my_int << endl;
cout << "Value of my_int:
" << my_int
<< endl;
cout << "Value of my_int--: " << my_int-- << endl;
cout << "Value of my_int:
" << my_int
<< endl << endl;
}
dfgsgsdggdsg