avr39ripe

ptrSwapTwoNum

Nov 23rd, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     int a{42};
  6.     int b{33};
  7.     int tmp{};
  8.  
  9.     int* ptrA{&a};
  10.     int* ptrB{&b};
  11.     int* ptrTmp{&tmp};
  12.  
  13.     *ptrTmp = *ptrA;
  14.     *ptrA = *ptrB;
  15.     *ptrB = *ptrTmp;
  16.  
  17.     std::cout << "a = " << *ptrA << " b = " << *ptrB << '\n';
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment