What is malloc doing in this code?

后端 未结 11 985
眼角桃花
眼角桃花 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:17

    sizeof(char)
    

    is safe. One shouldn't assume a single byte per character.

    My question is what are you doing programming if you don't know what malloc does?

    man malloc
    

    on a Linux system. On Windows. who knows? Probably 17 mouse clicks.

提交回复
热议问题