Created
May 5, 2017 08:35
-
-
Save tornikegomareli/dbe613caee0202491670216745686cc0 to your computer and use it in GitHub Desktop.
Swap Two Array's Address Helping the double Pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| using namespace std; | |
| void Init(int* Arr, int Size) | |
| { | |
| for (int i = 0; i < Size; i++) | |
| { | |
| *(Arr + i) = rand() % 100; | |
| } | |
| } | |
| void Print(int* Arr, int Size) | |
| { | |
| for (int i = 0; i < Size; i++) | |
| { | |
| cout << *(Arr + i) << " "; | |
| } | |
| } | |
| void Swap(int **board, int **new_board) { | |
| int *temp = *board; | |
| *board = *new_board; | |
| *new_board = temp; | |
| } | |
| int main() | |
| { | |
| const int Size = 3; | |
| int Array1[Size]; | |
| int Array2[Size]; | |
| int*N = Array1; | |
| int*M = Array2; | |
| int**Nptr = &N; | |
| int**Mptr = &M; | |
| Init(N, Size); | |
| Print(N, Size); | |
| cout << "\n"; | |
| Init(M, Size); | |
| Print(M, Size); | |
| cout << "\After Swap " << endl; | |
| Swap(Nptr, Mptr); | |
| Print(N, Size); | |
| cout << "\n"; | |
| Print(M, Size); | |
| cin.get(); | |
| cin.get(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment