If you were to do something like:
char array[2][5] = {"cars", "tags"} char array2[] = "computer"; There has been an implicit allocation of memory allocated equal to(for the first line):
sizeof(array); OR sizeof(char*10); Or however you want to do it.
Alternatively, one could do this:
char *ptr = "cars"; char *ptr2 = malloc(sizeof(*ptr2)*5); *ptr2 = "cars"; I know that if you are using pointers to explicitely allocate memory using malloc then it is good practice to free that pointer using free(ptr);
However, when you define things as above, are the following calls necessary on the same grounds as the explicit allocation of memory?
free(ptr); free(ptr2); free(array); free(array2); -- As an aside, all of the above delcarations/initializations are implicitely NULL-terminated strings, right?