For a homework of mine, I'm trying to mimic the way ArrayList was working in Java using C++. I want to create a class that contains an dynamically allocated array of pointers that are storing my user-defined class instances. However I was having a hard time fixing memory leaks, so I've decided to debug my code piece by piece and stumbled upon an error when trying to understand how to improve my code. After this long introduction my current problem is the following: I've created an array of integer pointers and then assigned them new pointers that are storing a automatically allocated integer. When trying to print the contents of this array I got nothing, however compiler does not complain about anything. If someone can show why am I mistaken while doing this I think I can fix my homework code as well.
int main() {
int** a = new int* [4];
for (int i = 0; i < 4; i++) {
int b = 0;
int* c = new int;
*c = b;
*(a + 1) = c;
}
for (int i = 0; i < 4; i++) {
cout << **a << endl;
}
delete[] a;
a = nullptr;
return 0;
}
This is the test code I've written to see how the structer works. Like I've said earlier the terminal shows only a huge chunk of nothing.