C++中strlen()用法


char str0[8] = { 'a','b','c','d','e','f','i','g' };
char str1[] = "abcdefig";
char str2[] = "01234\056789";
char str3[] = "abcse\0fgkij";

 

strlen(str0)    
strlen(str1)    
strlen(str2)
strlen(str3)

 

 str0的sizeof為8,導致沒有\0結束,因此strlen的返回是不可預期的。
str1會自動加\0結束所以是8。
str2的\056會被解釋成8進制數056表示的字符,因此strlen是9
str3的\0會被解釋為結束符


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM