一般一个malloc包含sizeof
,但是这一个不具有ⅰ+ 1,而不是:为什么在这个C代码中malloc i + 1的参数?
int main()
{
int i,n;
char * buffer;
printf ("How long do you want the string? ");
scanf ("%d", &i);
buffer = (char*) malloc (i+1);
if (buffer==NULL) exit (1);
更不用说,你不应该真的施放'malloc'的返回值。 – 2012-02-25 03:14:52