avr39-ripe

swap pointers

Apr 1st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T> void swap(T* const src, T* const dst)
  7. {
  8.     T tmp = *src;
  9.     *src = *dst;
  10.     *dst = tmp;
  11. }
  12.  
  13. int main()
  14. {
  15.     int a = 10;
  16.     int b = 20;
  17.  
  18.     cout << "a :" << a << " b: " << b << endl;
  19.     swap(&a, &b);
  20.     cout << "a :" << a << " b: " << b << endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment