References

  • Why do we use references? Instead of copying an object to a function argument, we can use a reference.
  • Creating a reference
int x = 3;
int &y = x; // y is a reference to x
  • Passing by reference
// pass by value
void my_function(my_object temp) {

}

// pass by reference
void my_function(my_object &temp) {

}

Pointers

int x = 3;
int *y = &x; // y is a pointer
int *z = y;  // z ia also a pointer
  • Dereferncing to get the value:
int w = *y;

In [ ]: