沉静
  
  首页 >>  
我的日历
分类日志
友情链接
最新评论
搜索日志
访问计数
获取 RSS
我的 Blog:
youalwayscan 最新的 20 条日志
[心情留言]
[点滴积累]
[好文共赏]
[C/C+基础]
[Unix/Linux基础]
[WxWidgets]
[VC/MFC]
全站 Blog:
全站最新的 20 条日志

 

sizeof()函数求值以及字符串分配内存注意事项

   C/C+基础2005-3-30 16:44
char str[] = "abcdefg";
sizeof(str)的值是8而不是7!
请注意。

char str1[] = "abcdefg";
char str2[] = "hijk";

分配内存后将两串相加后注入给新分配的内存:
char* str3 = (char*)memalloc(sizeof(str1)+sizeof(str2)-1);
strcpy(str3,str1);
strcat(str3,str2);


标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}