latest Post

C++ part-3(Reference Variable)





So hey guys let's start the third part of this series which was named as C++ it is a language section part and if you are not seen our other parts of this series i suggest you to see it first so you can easily understand this part of the series .
In this part of the series we our going to study about the Reference variable and do a program related to it which is useful you to understand the topic .We start with the theory and then go on the practical and if you have any suggestions or any doubt or any thing that you want to tell us please write in the comment box 
So let's start.................................


Reference variable :

It just like a pointer and have it's own  referent and any changes in the pointer or in the referent will also effect on the another one also if it is it's class or not it dose not matters where ever it is it will have an effect on another one.
We can not make an array of references . And the relation between reference to reference is not allowed to a reference .
A variable can easily declared a reference just by putting "&" in front of the variable. 

CODE


#include<iostream.h>
#include<conio.h>
void main( )
{
                  int i = 10;
                  int j = &i;(here j is a reference variable and i is referent)
                  cout<<"i ="<<i<<endl;
                  cout<<"j ="<<j<<endl;
                  i = 20;
                  cout<<"i ="<<i<<endl;
                  cout<<"j ="<<j<<endl;
                  j = 30;
                  cout<<"i ="<<i<<endl;
                  cout<<"j ="<<j<<endl;
}


Now you will see that when there is a change in the i there is a change in the j also so this is called reference variable and referent.
If you have any doubt ,suggestions ,questions regarding this or any article just comment in the comment box.
Lets meet again in the next part of the series or in the next article.

PART 4 (CONSTRUCTOR)


About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment