[cs13001] your mail

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Mar 3 13:56:41 EST 2014


> dear proffesor
> I have a question on the practice exam
> 
>   int a=3, b=4, c;
> 	    c = (a++) - (++b);
> 	    cout << a << " " << b << " " << c;
> 
> 
> would the output be
> 
> a=2
> 
> b=5
> 
> c=-2

The output would be 

  4 5 -2

Since both "a" and "b" are incremented, their value increases by
one. Now, a's is post increment (old value is used in the expression)
while b's is pre-increment (new value is used in the expression. The
expression is equivalent to

	c = 3 - 5;

Thanks,
-- 
Mikhail


More information about the cs13001 mailing list