Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
Practical - 03
1. Title: Write a function using reference variables as arguments to swap the
values of a pair of integers.
2. Outcome:
Gain clarity on how reference variables operate in C++.
Demonstrate the concept of call by reference and contrast it with call by
value.
Acquire hands-on practice in writing modular, reusable functions.
3. Objectives:
Understand the mechanics of passing variables by reference in a function.
Observe how modifications inside a function directly affect the original
variables.
Strengthen skills in writing clean, structured, and reusable C++ functions.
4. Nomenclature, Theory, Code, Result:
Nomenclature:
Reference variable: An alias for another variable, declared using &.
Swap function: A function that exchanges the values of two variables.
Theory:
In C++, when arguments are passed by value, the function works on copies,
leaving originals unchanged.
When arguments are passed by reference, the function works directly on the
original variables.
Swapping values is a classic demonstration: without references, the swap
won’t persist outside the function; with references, it will.
Code
Results