看板 Programming 關於我們 聯絡資訊
因為 strcpy(s, "z"); 之後 s[0] = 'z' s[1] = '\0' // 這個是 strcpy 作用的結果 s[2] = 'n' ... printf 碰到 '\0' 就停住了 ※ 引述《tame.bbs@bbs.ee.ncnu.edu.tw (漢唐中醫支持者)》之銘言: : #include<stdio.h> : #include<string.h> : int main() : { : char s[10]="abm"; : printf("%s\n",s); : strcpy(s,"z"); : printf("%s\n",s); : printf("%c%c%c",s[0],s[1],s[2]); : return 0; : } : - : 結果: : abm : z : z m : - : 為什麼第二行不會印出z m呢?反而到第三行才印出來? : s[2]在第二行消失了嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.194.15.150