C++ program to demonstrate call by reference


// call by reference in c++
#include<iostream.h>
#include<conio.h>
void swap(int * ,int *);
void main()
{
          int a,b;
          cout<<"Enter the value for a and b: ";
          cin>>a>>b;
          swap(&a,&b);
          cout<<"Values after swapping A= "<<a<<" B= "<<b;
          getch();
}
void swap(int *p1,int *p2)
{
          int t;
          t=*p1;
          *p1=*p2;
          *p2=t;
}

c++ progarm to implement call by reference : sample output
C++ program to demonstrate call by reference

C++ program to demonstrate call by value


//call by value method in c++
#include<iostream.h>
#include<conio.h>
int cube(int);
void main()
{
          int n;
          cout<<"Enter the number";
          cin>>n;
          n=cube(n);
          cout<<"Cube of the number is:"<<n;
          getch();
}
int cube(int n)
{
          n=n*n*n;
          return n;
}

Output
call by value, pass by value c++ progarm: Sample output
C++ program to demonstrate call by value

C++ program to find the vowels and consonants in a string


#include<iostream.h>
#include<conio.h>
void main()
{
char a[25],*p[25],v[25],c[25];
int i,j,k=0,l=0;
cout<<"Enter the string\n\n";
cin>>a;
for(i=0;a[i]!='\0';i++)
{
p[i]=&a[i];
}
p[i]=&a[i];
for(i=0;*p[i]!='\0';i++)
{
if(*p[i]=='a'||*p[i]=='e'||*p[i]=='i'||*p[i]=='o'||*p[i]=='u')
{
v[k]=*p[i];
k++;
}
else
{
c[l]=*p[i];
l++;
}
}
v[k]='\0';
c[l]='\0';
cout<<"\n\nVowels\n\n";
for(i=0;v[i]!='\0';i++)
{
cout<<v[i]<<" ";
}
cout<<"\n\nConsonents\n\n";
for(i=0;c[i]!='\0';i++)
{
cout<<c[i]<<" ";
}
getch();
}

C++ program to find the vowels and consonants in a string