------------------------------------------------------------------------------
MC logo
Call-by-Reference
[^] Functions
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Call-by-Reference] [Call-by-Value-Result] [Call-by-Name] [Dyn Link Example] [Dyn Link Example] [C++ Translation of Java Dyn Link] [Variable Location] [Parameter Passing Method Exercise]
ref.cpp
#include <iostream>

using namespace std;

void f(int &a, int &b)
{
        a = a + 3;
        b = b + 5;
}

main()
{
        int x = 10;
        int y = 25;
        f(x,y);
        cout << x << " " << y << endl;
        x = 10;
        f(x,x);
        cout << x << endl;
}


Output is:
13 30
18
When the second call runs, both a and b are aliases for x in the main.