I have the following array declared inside a header file.
static const float elementsArray[300] = { ... };
I want to do:
float *elementsPointer = &elementsArray[0];
I'm sure I can do that, but... Do I need to release elementsPointer with delete?
Do I need to do anything else?
Thank you.
No. The memory that elementsPointer points to is statically allocated and does not require a call to free.
Do I need to release elementsPointer with free
Exactly the opposite - you must not free that particular pointer value since it hasn't been allocated with malloc() or calloc().
If that pointer might sometimes be assigned with a value that was dynamically allocated you'll need to arrange (maybe with a flag) to call free() only with those memory blocks (if the code using elementsPointer is responsible for freeing that memory).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With