types of functions and their usage

#include<iostream>
using namespace std;
int a=56,b=56,c=56;
int passbyvalue(int x);
void passbyreference(int &x);
void passbypointers(int *x);
int main(){
cout<<endl<<"the program will tell three ways to use functions to store  value "<<endl;
cout<<" 1 = Pass by value"<<endl<<" 2 = pass by reference  "<<endl<<" 3 = pass by pointers "<<endl;

cout<<"-------------------------------------------------------------------------------"<<endl;

cout<<" the value of a  now = "<<a<<endl<<"and after passbyvalue "<<endl;

a=passbyvalue(a);

cout<<"the value of a now = "<<a<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;

cout<<" the value of b  now = "<<b<<endl<<"and after passbyreference "<<endl;

passbyreference(b);

cout<<"the value of b now = "<<b<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;

cout<<" the value of c  now = "<<c<<endl<<"and after passbypointers "<<endl;

passbypointers(&c);

cout<<"the value of c now = "<<c<<endl;

cout<<"-------------------------------------------------------------------------------"<<endl;

}
int passbyvalue(int x){
x*=2;
return x;
}

void passbyreference(int &x){
x*=2;
}

void passbypointers(int *x){
*x*=2;
}




Previous
Next Post »

EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng

Comments:

Disqus Shortname