What does allocating memory of size char * do?

Viewed 5002
char    *str;
str = malloc(sizeof(char) * 5);

This code allocates 5 consecutive slots of memory to the variable str, which is of type char *.

char    *str;
str = malloc(sizeof(char *) * 5);

This is supposed to allocate 5 times the memory of an array of char. But since an array of char has no size until we declare it, what does this statement actually do?

5 Answers
Related