Cpp- Program for call by reference

 

 Advanced C++ : Introduction to C++ & C++ Structures | by Khushboo Patel |  Medium

 

  //Program for call by reference.
#include<iostream>
#include<conio.h>
int main()
{
    clrscr();
    void swap(int *a, int *b);
    int x=10;
    int y=20;

cout<<"\n\t\t\tOUTPUT";

cout<<"\n\t\t\t------------";
    cout << "\n\t\tBefore swapping";
    cout<<"\n\t\t\tx="<<x;
    cout<<"\n\t\t\ty="<<y;
    swap(&x, &y);
    cout<<"\n\t\tswapping";
    cout<<"\n\t\t\tx="<<x;
    cout<<"\n\t\t\ty="<<y;
    getch();
    return 0;
}
void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

 

 OUTPUT

--------------

Before swapping

        x=10

        y=20

After swapping

        x=20

        y=10

 

 

Comments

Popular posts from this blog

MS Word

DS - Representation of linked list in memory.

NUMERICAL ABILITY