I created a char array like so:
char arr[3] = \"bo\";
How do I free the memory associated with array I named \"arr\"?
Local variables are automatically freed when the function ends, you don't need to free them by yourself. You only free dynamically allocated memory (e.g using malloc
) as it's allocated on the heap:
char *arr = malloc(3 * sizeof(char));
strcpy(arr, "bo");
// ...
free(arr);
More about dynamic memory allocation: http://en.wikipedia.org/wiki/C_dynamic_memory_allocation