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

fayehadith 1年前 已收到1个回答 举报

zuguoshensheng 花朵

共回答了21个问题采纳率:85.7% 举报

(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;//释放缓存

1年前

3
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.473 s. - webmaster@yulucn.com