diff options
author | Oskar <[email protected]> | 2024-09-06 17:10:32 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-06 17:10:32 +0200 |
commit | cc01160a3f0fdcb27eb931f67e85d783d0f5626d (patch) | |
tree | 3574e221430241d8b9e11c73ae27cc1301b015f9 /6p22.cpp | |
parent | 9b73f5889937d88796b45126f6165027fecd3436 (diff) |
more
Diffstat (limited to '6p22.cpp')
-rw-r--r-- | 6p22.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/6p22.cpp b/6p22.cpp new file mode 100644 index 0000000..91f4bcd --- /dev/null +++ b/6p22.cpp @@ -0,0 +1,41 @@ +#include <iostream> + +/* + * + * 6.22 + * + * + */ + +void SwapIntPtr(int **p1, int **p2) { + + int *p1tmp = *p1; + *p1 = *p2; + *p2 = p1tmp; +} + +void SwapIntPtrREF(int *&p1, int *&p2) { + + int *p1tmp = p1; + p1 = p2; + p2 = p1tmp; +} + +int main () { + + int i1 = 10; + int i2 = 21; + int i3 = 13213; + int i4 = 2331; + int *p1 = &i1; + int *p2 = &i2; + int *p3 = &i3; + int *p4 = &i4; + std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl; + SwapIntPtr(&p1, &p2); + std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl; + std::cout << "\np3 " << p3 << "\np4 " << p4 << std::endl; + SwapIntPtrREF(p3, p4); + std::cout << "p3 " << p3 << "\np4 " << p4 << std::endl; + return 0; +} |