memory and reference with definition and example of program.

Memory and Reference.

 Memory

Computer memory is a collection of different consecutive memory location . These memory locations are numbered locations are numbered sequentially. Each variable is created at a unique location in memory location is known as address. 

Reference

A reference is the act of mentioning of something in writing to back up a statement of information. A reference is the value that enables a program to indirect access a particular data, such as variable value record , in the computer memory or some other storage.


A program may declare many variables for different tasks, A variable declaration reserves specific amount of space in memory for a particular variable. The variable name is used to  refer to the memory location. it allows the user to access a value in the memory. The computer refers to the memory using an address.
    
         A variable declaration association following three attributes to a variable.
  • Variable name
  • Variable type
  • Variable memory address
The following statement declares an integer variable ;
 
        int a;

The name of variable is a and data type of variable is  int. The address of the variable is unknown . Computer creates the variable at  any available location in the memory. The memory address ins hexadecimal number that refers to a particular location in the memory 
The variable is created in the memory as follows/

                    

                                                                0x0065fdf0

                                                                                         Int

                                                                        a

 The above box represent the memory location allocated for the variable  a. The hexadecimal value above the box is its assumed address. The variable will occupy 2 bytes or 4 bytes in memory depending on the type of computer. 

The actual address of the variable can be displayed by using reference operator &.
It is also known as address operator. The reference operator is used to access the memory address of a variable . The following statement will displayed the address  of a. 



example


            #include<iostream.h>
           #include<conio.h>
            voide main()
                    {

                            int n =12;
                            cout<<" The value of n: "<< n<<endl;
                            cout<<"The address of n:"<<&n<<endl;
                                    getch();
                    }