Functions with pass by reference

A variable is a named location in memory. When we declare a variable in C++, the operating system allocates space for the variable and tells the program the address that it has set aside.


Text of video
1
2
3
4
5
6
7
8
9
10
//Addresses
#include<iostream>
using namespace std;
int main()
{ int x=5;
  cout<<"The value of x is: "<<x<<"\n";
  cout<<"The address of x is: "<<&x<<"\n";
  system("pause");
  return 0;
} //main
CODE
The value of x is: 5
The address of x is: 010DFBD0
Press any key to continue . . .

In the illustration, the variable x is at memory location 0x010DFBD0. Memory addresses are always shown in hexadecimal. The location may be different each time you run the program.
address

When the program refers to x, the compiler will use the contents of the assigned location in memory.

NEXT: Finding half the value