Call by Value & Call by Reference using Function in C++


Example Program

Here is the simple program for printing call by value and call by reference using function in C++.

Source Code Example : 1

#include <iostream>
using namespace std;
void change(int data);
int main()
{
    int data=3;
    cout<<"Value of the data is: "<<data<<endl;
    change(data);
    return 0;
}
void change(int data)
{
    data=5;
    cout<<"After changing :"<<endl;
    cout<<"Value of the data is: "<<data<<endl;
}
To download raw file Click Here

Output

Value of the data is: 3
After changing :
Value of the data is: 5


Source Code Example : 2

#include<iostream>
using namespace std;
void swap(int *x, int *y)
{
    int swap;
    swap=*x;
    *x=*y;
    *y=swap;
}
int main()
{
    int x=500, y=100;
    cout<<"\nValue of x is: "<<x<<endl;
    cout<<"\nValue of y is: "<<y<<endl;
    cout<<"\nAfter swapping :";
    swap(&x, &y);
    cout<<"\nValue of x is: "<<x<<endl;
    cout<<"\nValue of y is: "<<y<<endl;
    return 0;
}
To download raw file Click Here

Output

Value of x is: 500

Value of y is: 100

After swapping :
Value of x is: 100

Value of y is: 500

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes