Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Referencing

#include <iostream>

using namespace std;

int main() {
  int a = 10;
  int &r = a;

  r = 25; // a becomes 25 as well
  // referencing doesn't consume memory, since it is not a pointer

  int b = 30;
  r = b; // this will also change a and r to 30

  cout << a << endl << r << endl;

  // r : variable
  // *r : store the address
  // &r : reference
}