已知char *p=”Good\0Morning!”;则表达式strlen(p)的值是-------.详解,..

问题描述:

已知char *p=”Good\0Morning!”;则表达式strlen(p)的值是_______.详解,..
1个回答 分类:综合 2014-09-23

问题解答:

我来补答
(1) char*str={"hello"}; intvalid_len=strlen(str);//获取有效字符串长度,此时valid_len为5 (2)最大长度与你内存的容积有关,是没有具体值限制的; (3)filename为一个包含路径的文件名字符串,如"c:\\test.txt" (4) intn=2; charNthChar=str[n-1];//获取第n个字符,此时NthChar为'e' (5)intASCII_code=(int)NthChar;//直接强制转换就可获取其整数值了,ASCII_code为101,即'e'的ASCII码 (6)charascii_2_ch=(char)ASCII_code;//直接强制转换就可以了,ascii_2_ch此时为'e' (7) char*str2={"world"}; char*buff=newchar[strlen(str)+strlen(str2)+1];//分配缓存大小 strcpy(buff,str);//把str内容拷贝到buff,此时buff中内容为{"hello"}; strcat(buff,str2);//合并这个两个字符串,此时buff中内容为{"helloworld"} deletebuff;//释放缓存
 
 
展开全文阅读
剩余:2000
下一页:请说清为什么