add pointer

add "dynamic" heap array
add polymorphic
This commit is contained in:
2025-03-26 12:44:05 +01:00
parent abb1ea4a38
commit 4b6ac6a484
13 changed files with 339 additions and 1 deletions
+13
View File
@@ -51,6 +51,19 @@ int main()
printArray(numbers2);
printArray(numbers2, std::size(numbers2));
// "dynamic" (heap) arrays
int count2 = 10;
int* heapNumbers = new int[count2];
heapNumbers[0] = 10;
int* pHeapNumber = heapNumbers;
for (size_t i = 0; i < count2; i++)
{
cout << pHeapNumber << ": " << *pHeapNumber << " ";
pHeapNumber++;
}
delete[] heapNumbers; // CAUTION - heap arrays have to be deleted with delete[] not delete
heapNumbers = nullptr;
// stl collections
vector<int> numbers6;
vector<int> numbers7 = { 0, 1, 2, 3 };