Cpp Program for call by value.


 

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

 //Program for call by value
#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

Post a Comment

Popular posts from this blog

DATA STRUCTURE - Searching methodes

Data structure - Sorting methodes

Cpp-Program for Constructor and Distructure with Output