Initializing and using a reference. - C++ Data Type

C++ examples for Data Type:Reference

Description

Initializing and using a reference.

Demo Code

#include <iostream>

int main(int argc, const char* argv[]) {
    int x = 3;//from   w  w  w.j a v  a 2s. co  m
    int& y = x;

    std::cout << "x = " << x << std::endl << "y = " << y << std::endl;

    y = 7;  // modifies x

    std::cout << "x = " << x << std::endl << "y = " << y << std::endl;

    return 0;
}

Result


Related Tutorials