This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Showing posts with label Write a function using reference variables as arguments to swap the values of a pair of integers in a program. Show all posts
Showing posts with label Write a function using reference variables as arguments to swap the values of a pair of integers in a program. Show all posts

Wednesday, March 15, 2023

Write a function using reference variables as arguments to swap the values of a pair of integers in a program

March 15, 2023 0
 here's an example program that swaps the values of two integers using a function with reference variables:#include <iostream>using namespace std;// function to swap two integers using reference variablesvoid swap(int& x, int& y) {    int temp = x;    x = y;    y = temp;}int main() {    int num1 = 10, num2 = 20;        // before swapping    cout << "Before swapping:...

Slider Widget