C++ program to swap two numbers using temporary variable

C++ program to swap two numbers using temporary variable. This program will change the numbers position using the C++. Swapping the numbers means it will interchange the number which are allocated in the c++ programming language.

#include <iostream>
using namespace std;
int main()
{
int a = 50, b = 10, temp,c;
cout << "Before" << c;
cout << "a = " << a << ", b = " << b << c;
temp = a;
a = b;
b = temp;
cout << "\nAfter" << c;
cout << "a = " << a << ", b = " << b << c;
return 0;
}

Output:

Before a = 50, b = 10

After a = 10, b = 50

What is temporary variable in c++ programming

A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location. It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived.