Tuesday 16 December 2014

            Scope resolution is an operator(::) which gives access to control the global variables in-spite of local variables exist.

Syntax:

                          ::variable_name;
Tell me the out of bellow program.


Compile time error. Global variable has not declared.But, You are trying to print undeclared value.







How to Create reference to Variable:


1)For existing variables we can create reference by the following syntax.


2)Variable declaration and initialization need to be at the same place.


       The following syntax is invalid. Because Variable declaration and initialization are not at the same place.
3)We can give reference to any number of variables. At this instant the addresses for all remains same.

 4) we can create reference for references(reference to reference)
5) we can’t refer the constants.
6) we can’t change references from one variable to another variable.

7)we can change address of pointer variable through references

8) Referece to pointers:

9) Array of references and array of pointers possible. But reference of references is not possible.

Example program to perform various arithmetic calculations.

Rules for reference variables:

1)we can’t change the reference.

2)declaration at one place, initialization at some other place is not possible.

        int x=100;
        int *p=&x;
        int &y=*p;        //valid
        int &y=100;      //not valid

3)array of pointers possible, array of references possible, array of addresses possible.

4)references for int,float,char is possible. References for pointers also possible

Benefits of reference variables:

1)It gives simplicity.

2) by using reference operator,we can refer address of one function variable to address of another function(calling function).

3) it is possible to make changes to the original function data by using reference operator instead of passing address of variable.