What is malloc doing in this code?

后端 未结 11 975
眼角桃花
眼角桃花 2021-01-01 04:59

Could you explain following code?

str = (char *) malloc (sizeof(char) * (num+1));
  1. What is malloc doing here?
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 05:09

    malloc allocates memory.

    num+1 as num is the number of characters in the string and +1 for the null terminator

提交回复
热议问题