diff options
Diffstat (limited to 'tests/exec/ref6.cpp')
-rw-r--r-- | tests/exec/ref6.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/exec/ref6.cpp b/tests/exec/ref6.cpp new file mode 100644 index 0000000..3737786 --- /dev/null +++ b/tests/exec/ref6.cpp @@ -0,0 +1,20 @@ +#include <iostream> + +int &f(int b, int &x, int &y) { + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + if (b) return x; else return y; +} + +int main() { + int x = 42; + int y = 43; + int &r = f(1, x, y); + // now r is an alias for x + r = 12; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + f(0,x,y) = 13; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; +} |