diff options
| -rw-r--r-- | Project1/c_array.cpp | 14 | ||||
| -rw-r--r-- | Project1/main.cpp | 8 |
2 files changed, 15 insertions, 7 deletions
diff --git a/Project1/c_array.cpp b/Project1/c_array.cpp index f504839..1423273 100644 --- a/Project1/c_array.cpp +++ b/Project1/c_array.cpp @@ -1,27 +1,31 @@ #include <iostream> #include <ostream> #include "c_array.h" +#include <string.h> using std::cin; using std::cout; using std::endl; -void DoubleArraySize(int*& array, size_t size) +void DoubleArraySize(int*& array, size_t SIZE) { - int* newArray = nullptr; - newArray = new int[size * 2]; + int *newArray = new int[SIZE * 2]; - for (auto i = 0u; i < size; ++i) + for (auto i = 0u; i < SIZE*2; ++i) { newArray[i] = array[i]; + } delete[] array; array = newArray; - size *= 2; + + SIZE *= 2; + + PrintArray(array, SIZE); } void PrintArray(int* array, size_t size) diff --git a/Project1/main.cpp b/Project1/main.cpp index 5dd3c7c..7862a8b 100644 --- a/Project1/main.cpp +++ b/Project1/main.cpp @@ -16,12 +16,16 @@ int main() constexpr size_t SIZE = 101; int* array = new int[SIZE]; - PrintArray(array, SIZE); + for (auto i = 0u; i < SIZE; ++i) + { + array[i] = static_cast<int>(i); + } - DoubleArraySize(array, SIZE); PrintArray(array, SIZE); + DoubleArraySize(array, SIZE); + delete[] array; return 0; }
\ No newline at end of file |