char** surname;
surname = (char**) malloc(size*sizeof(char*));
char* middle_initial;
middle_initial = (char*) malloc(size*sizeof(char));
for(int i = 0; i<5;i++){
surname[i] = (char*) malloc(surname_max*sizeof(char));
middle_initial[i] = *(char*) malloc(middle_max*sizeof(char)); // Please focus on this line
}
surname
is a double char pointer
, and it makes sense that surname[i]
is the i
-th pointer pointed to by surname
.
However, middle_initial confuses me. Is middle initial[i]
the i
-th character pointer? If so, why does malloc
returns value call for a dereferenced *(char *)
instead of (char *)
during debugging?
** Follow up question** I would like middle_initial [i] to be 6 char pointers each having the capacity to point to 1 character. What can I modify above to do such that?