把握命运,追逐梦想

对自己所做的事要有兴趣,同时还要能够坚持不懈

统计

留言簿(1)

阅读排行榜

评论排行榜

malloc的错误和正确用法

#include<stdlib.h>
#include
<stdio.h>
int main()
{
    
char *p;
    p 
= (char*)malloc(10);
    p 
= "Hello";
    printf(
"%s\n",p);
    
return 0;
}


#include
<string.h>
#include
<stdio.h>
#include
<malloc.h>

int main()
{
    
char *str;
    str 
=(char*)malloc(10);
    strcpy(str,
"Hello");
    printf(
"String is %s",str);
    free(str);
    
return 0;
}

posted on 2009-07-28 16:42 把握命运 阅读(209) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理