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

C++ program to implement insertion sort


// insertion sort c++

#include<iostream.h>
#include<conio.h>
void main()
{
          int a[20],i,j,n,k,*p,temp;
          p=a;
          clrscr();
          cout<<"Enter the value for n:";
          cin>>n;
          cout<<"\nEnter the elements:";
          for(i=0;i<n;i++)
          {
                   cin>>*(p+i);
          }
          for(k=1;k<=n-1;k++)
          {
                   temp=p[k];
                   j=k-1;
                   while((temp<*(p+j)) && (j>=0))
                   {
                             p[j+1]=p[j];
                             j=j-1;
                   }                                                                                                                                                                                                                                                                                                        p[j+1]=temp;
          }
          cout<<"\nArray after sorting\n\n";
          for(i=0;i<n;i++)
          {
                   cout<<*(p+i)<<"\t";
          }
          getch();
}