Advertisement
AshfaqFardin

Swap Values

Jul 29th, 2021
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(double *value1, double *value2) {
  6.     double temp = *value1;
  7.     *value1 = *value2;
  8.     *value2 = temp;
  9. }
  10.  
  11. int main()
  12. {
  13.     double first_value = 2.3;
  14.     double second_value = 3.5;
  15.    
  16.     cout << "Value before swapping\n";
  17.     cout << first_value << "\n";
  18.     cout << second_value << "\n";
  19.    
  20.     cout << "\n";
  21.     swap(&first_value, &second_value);
  22.    
  23.     cout << "Value after swapping\n";
  24.     cout << first_value << "\n";
  25.     cout << second_value << "\n";
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement