Click To Get Off-Campus Placement Jobs Info !!!
Capgemini Recruitment Process 2020 – Updated Test Pattern and Selection Process in Details Latest Pattern !!
Program Discussion :: Basics
Home > Programs > Basics

71 / 244

Write a program, swapping function by passing value using call by reference?

Answer:

#include <iostream>
using namespace std;
/* function declaration */
void swap(int &x, int &y);
int main () {
   /* local variable declaration: */
   int a = 100;
   int b = 200;
   cout << "Before swap, value of a :" << a << endl;
   cout << "Before swap, value of b :" << b << endl;
   /* calling a function to swap the values using variable reference.*/
   swap(a, b);
   cout << "After swap, value of a :" << a << endl;
   cout << "After swap, value of b :" << b << endl;
   return 0;
}

Asked In :: Wipro Syntel Inc. Sapient

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: