I also had read in lots of books that arrays and pointers are closely related and I was expecting it to work. |
Related yes, but you forgot the details.
An array refers to a block of memory that contains values.
A pointer is a small variable that contains one value: an address.
Think an array as a house and pointer as a postit note that has an address of a house. Your
float **dens_old;
writes a postit that has random characters on it. They might look like an address, but even if there is a house, it won't be your house. Crashing in into strangers house is not ok.
In this the house is real and the note we give to the function is valid; it gets the address of your house:
1 2 3
|
void func( float* note );
float house[42];
func( house );
|
Related example:
int foo = 7;
1 2 3 4
|
int* bar; // uninitialized pointer
int* gaz = &foo; // initialized pointer
*bar = 42; // error, address unknown
*gaz = 42; // ok, effectively does: foo = 42;
|
Perhaps you were on a chapter about
dynamic memory allocation?
That is a good to understand topic, but you should prefer the C++ Standard Library Containers that do the manual chores for you, safely.
I also am using free IDE (code block) and can not use C++ 11. |
IDE uses a compiler and that compiler can be replaced.
Alternatively, the current compiler might already have support for recent C++, but requires explicit enablement. The IDE should offer ways to pass such (command line) options to the compiler.