Hi friends,
Here one more basic concept in c and c++ that is of basic for ubderstanding of what poniter can do.
Basicly in c++ like language we can not return more than one value taht is one value is returned using return value, but if we want to return more value than we should modify that statement by using pointers to make it returning more than one value.
Here in this illustrative example i have instead passe argument as refrence rather value. In call-by-value we simply pass variable values as argum,ent to the function called and in that case whatever changes that made to inside does not reflected in original variable.
However to overcome this there is very good convention call-by-refrence method in which we passing variable address instead of value and then whatever changes made inside function are directly refrelected in original variable.
So by using this method we are able to get than one returned values whenever we need it.
Here first i have provided link if you directly download .cpp files:
calllbyref.cpp
#include <iostream.h>
#include <conio.h>
void swap(int *num1,int *num2);
void main()
{
clrscr();
int var1,var2;
cout<<"Enter two numbers :"<<endl;
cin>>var1;
cin>>var2;
cout<<"In main before swap:"<<var1<<" "<<var2<<endl;
swap(&var1,&var2);
cout<<"In main:"<<var1<<" "<<var2<<endl;
getch();
}
void swap(int *num1,int *num2)
{
int temp;
temp=*num1;
*num1=*num2;
*num2=temp;
cout<<"In swap:"<<*num1<<" "<<*num2<<endl;
}
Below is the you will see after running callbyref.cpp file:
So thats all about call hy refrence hope you have enjoy it.
If you want to see another c++,c,java,vb.net,visual basic visit my site:
Here one more basic concept in c and c++ that is of basic for ubderstanding of what poniter can do.
Basicly in c++ like language we can not return more than one value taht is one value is returned using return value, but if we want to return more value than we should modify that statement by using pointers to make it returning more than one value.
Here in this illustrative example i have instead passe argument as refrence rather value. In call-by-value we simply pass variable values as argum,ent to the function called and in that case whatever changes that made to inside does not reflected in original variable.
However to overcome this there is very good convention call-by-refrence method in which we passing variable address instead of value and then whatever changes made inside function are directly refrelected in original variable.
So by using this method we are able to get than one returned values whenever we need it.
Here first i have provided link if you directly download .cpp files:
calllbyref.cpp
#include <iostream.h>
#include <conio.h>
void swap(int *num1,int *num2);
void main()
{
clrscr();
int var1,var2;
cout<<"Enter two numbers :"<<endl;
cin>>var1;
cin>>var2;
cout<<"In main before swap:"<<var1<<" "<<var2<<endl;
swap(&var1,&var2);
cout<<"In main:"<<var1<<" "<<var2<<endl;
getch();
}
void swap(int *num1,int *num2)
{
int temp;
temp=*num1;
*num1=*num2;
*num2=temp;
cout<<"In swap:"<<*num1<<" "<<*num2<<endl;
}
Below is the you will see after running callbyref.cpp file:
So thats all about call hy refrence hope you have enjoy it.
If you want to see another c++,c,java,vb.net,visual basic visit my site:
