How do you completely delete an array in C to the point that you can reinitialize it?

How to: How to recover memory and delete an array to such an extent that you can initialize it again later in the program? For instance:

char * array[][2] = {
{"bla","bla","bla"},
{"blabity","blabity","bla"}
}
// Delete array
sizeof(array) == NULL;
char * array[][2] = {
{"bla","bla","bla"},
{"blabity","blabity","bla"}
}
+3
source share
4 answers

You can not. An array defined using parentheses (outside scope 1 ) is compiled directly into your program and therefore cannot be freed. However, you can reinitialize it by simply returning the original content. If you want to be able to create and destroy an array as you wish, you need to save it as a pointer and use mallocand free.

1: , , , , . , .

+5

, - . - .

+2

/ - .

, , , - , (, malloc).

+2

" malloc": malloc(), calloc(), realloc() free().

#include <stdlib.h>!

+1

All Articles