Answers for "REFERENCE C++"

C++
3

reference function in c++

// function definition to swap the values.
void swap(int &x, int &y) {
   int temp;
   temp = x; /* save the value at address x */
   x = y;    /* put y into x */
   y = temp; /* put x into y */
  
   return;
}
Posted by: Guest on June-13-2020
1

REFERENCE C++

int& r = i;
Posted by: Guest on September-12-2021
0

reference variablesr in c++

Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7
Posted by: Guest on December-13-2020
0

reference variablesr in c++

#include <iostream>
 
using namespace std;
 
int main () {
   // declare simple variables
   int    i;
   double d;
 
   // declare reference variables
   int&    r = i;
   double& s = d;
   
   i = 5;
   cout << "Value of i : " << i << endl;
   cout << "Value of i reference : " << r  << endl;
 
   d = 11.7;
   cout << "Value of d : " << d << endl;
   cout << "Value of d reference : " << s  << endl;
   
   return 0;
}
Posted by: Guest on December-13-2020
0

reference function in c++

#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;
}
Posted by: Guest on June-13-2020

Code answers related to "REFERENCE C++"

Browse Popular Code Answers by Language