add casts

add inline
add template
This commit is contained in:
2025-09-23 18:17:48 +02:00
parent 3b35b973c9
commit bc4b9f1691
9 changed files with 142 additions and 3 deletions
+24
View File
@@ -31,6 +31,8 @@ int main()
int grid[COLUMNS * ROWS] = {};
grid[calculateIndex(3, 2)] = 10; // 4th column, 3rd row
//int grid2[10][10];
// size has to be always constant
const int count = 10;
int numbers4[count] = {};
@@ -58,6 +60,28 @@ int main()
delete[] pNumbers; // CAUTION - heap arrays have to be deleted with delete[]
pNumbers = pNumbers2 = nullptr;
// 2d heap array
int** pGrid = new int*[10];
cout << "grid starts at " << pGrid << endl;
for (size_t i = 0; i < 10; i++)
{
pGrid[i] = new int[10];
cout << i << ". row: " << &pGrid[i] << endl;
for (size_t j = 0; j < 10; j++)
{
cout << i << "/" << j << ": " << &pGrid[i][j] << endl;
}
}
// delete inner arrays first
for (size_t i = 0; i < 10; i++)
{
delete[] pGrid[i];
pGrid[i] = nullptr;
}
delete[] pGrid; // delete outer array second
pGrid = nullptr;
// stl collections
vector<int> numbers5;
vector<int> numbers6 = { 0, 1, 2, 3, 4 };