Question: i have a little question in relation to the free() function of C.

I allocate in a program a multidimensional array with this code :

```
char **newMatrix( int N ){
    int i,j;
    char **a = malloc(sizeof *a * N);
    if (a)
    {
      for (i = 0; i < N; i++)
      {
        a[i] = malloc(sizeof *a[i] * N);
      }
    }

```

at the end of the program the array is full of characters. 
So i do this to deallocate the memory.

```
void freeArray(char **a, int m){
    int i;
    for (i = 0; i < m; ++i) {
        free(a[i]);
    }
    free(a);
}

```

My question is , how can I really check if the free() function works well , and deallocate all the memory? 
I ask you because I have tried to print the matrix after the freeArray , and the result is that the values are still stored in the a[i][j] columns and rows .

Sorry if it will be a stupid question , i'm new of C programming!

Answer: 
free will not clear the memory for you. It just marks it as available for the OS to reallocate somewhere else. People tend to assign NULL to a pointer after freeing to prevent accidental reuse. If you want to be sure what your code is doing, you could memset the allocated space to a known value before freeing. To be honest, just print out how much data you mallocate and make sure you free the same size of data from the same pointer.
free() will only remove the reference to memory pointed to, by the pointer passed to it. 

Once a pointer is passed to free() and the free() returns a success(which always is..), the pointer should never be used.

To avoid this usage, which is a illegal reference, a pointer variable should always be assigned NULL after it is passed to free().