Sei sulla pagina 1di 9

DAY4

Program No. 9

Factorial value using function

REFERENCE VARIABLE
C++ introduces a new kind of variable as the reference variable. A reference variable provides an alias(alternative name) for a previously defined variable.
A reference variable must be initialized at the time of declaration

Program No. 10

Reference Variable

Program No. 11

Input two numbers and interchange them

Reference as parameters
C++ supports passing references as function parameter more safely than parameters.

Program No. 12

Input two numbers and interchange them using reference as parameters

Reference as return type


A C++ program can be made easier to read and maintain by using references rather than pointers.
A C++ function can return a reference in a similar way as it returns a pointer. When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement. For example, consider this simple program:

Program NO. 13

Reference as return type

Potrebbero piacerti anche