Assign other value to a variable from two possible values | CPP program to change value of x according to its current value . ; Function to alternate the values ; Main function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void alternate ( int & a , int & b , int & x ) { x = a + b - x ; } int main ( ) { int a = -10 ; int b = 15 ; int x = a ; cout << " x ▁ is ▁ : ▁ " << x ; alternate ( a , b , x ) ; cout << " After change " cout << " STRNEWLINE x ▁ is ▁ : ▁ " << x ; }