1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#define show(a) ( std::cout << ' ' << #a << " == " << (a) << ' ' )
#define showln(a) ( show(a) << '\n' )
#define show_assignment(lhs,rhs) { std::cout << "\tafter " << #lhs << " = " << #rhs \
<< " => " ; show(rhs) ; showln(lhs) ; }
void changes ( int& x, int& y, int& z )
{
std::cout << "\n\tfunction changes()\n\t------------------\n" ;
std::cout << "\ton entry => " ; show(x) ; show(y) ; showln(z) ;
int d ;
d=x+y ; show_assignment( d, x+y ) ;
z=d+1 ; show_assignment( z, d+1 ) ;
x=d-2*y ; show_assignment( x, d-2*y ) ;
std::cout << "\tat return => " ; show(x) ; show(y) ; showln(z) ;
}
int main()
{
int a = 3, b = -5, c = 2 ;
std::cout << "in main => " ; show(a) ; show(b) ; showln(c) ;
changes(a,b,c);
std::cout << "\nafter changes(a,b,c) => " ; show(a) ; show(b) ; showln(c) ;
changes (c,a,b);
std::cout << "\nafter changes(c,a,b) => " ; show(a) ; show(b) ; showln(c) ;
}
|