"code
"class="
cpp">/*
strlen函式解析
*/# include
# include
# include
int main(void);
int len2 =strlen(c2);
printf(
"len2 = %d\n
", len2); //
..error..len2 = 9
char c3 = ;
int len3 =strlen(c3);
printf(
"len3 = %d\n
", len3); //
len3 = 5
char c4[10] = "
abs"
;
int len4 =strlen(c4);
printf(
"len4 = %d\n
", len4); //
len4 = 3
char c5[4
];
int len5 =strlen(c5);
printf(
"len5 = %d\n
", len5); //
len5 = 5
/*c5[0] = '\0';
len5 = strlen(c5);
printf("len5 = %d\n", len5); //len5 = 0
*/c5[
4] = '\0'
; len5 =strlen(c5);
printf(
"len5 = %d\n
", len5); //
len5 = 4
return0;
} /*總結:如果字元陣列,
1.用字串(雙引號"")初始化,用strlen函式可以求出該字串的長度
2.用字元陣列的形式()初始化,必須在最後面新增乙個元素'\0'才可以。
*/
C語言 strlen 函式易錯點
strlen函式解析 include include includeint main void int len2 strlen c2 printf len2 d n len2 error.len2 9 char c3 int len3 strlen c3 printf len3 d n len3 l...
strlen與pow易錯點
string.h strlen 作用 返回字元陣列的長度 錯誤例子 include include include int main int argc,char const argv 結果顯示為 顯示結果 答案 strlen所作的僅僅是乙個計數器的工作,它從記憶體的某個位置 可以是字串開頭,中間某個...
C語言易錯點
c語言易錯點 1.每個c語言程式中main函式是有且只有乙個的。2.演算法可以沒有輸入,但必須要有輸出。3.在函式中不可以再定義函式。4.break可用於迴圈結構和switch語句。5.break和continue的區別在於前者是跳出迴圈,後者是結束本次迴圈。6.逗號的運算子的級別最低。7.c語言對...