我寫了下面的C程序:好奇陣列覆蓋操作
int main()
{
char a[1];
char b[6]="hello\0";
int c, i;
for(i = 0; (c = getchar()) != EOF; i++)
a[i] = c;
for(i = 0; i < 5; i++)
printf("%c", b[i]);
}
爲什麼當我送你「拜拜」,在輸入程序打印「helby」? 我認爲'b'應該保存在b [0]中的[0],'y'和b [1]中的'e'中。 謝謝您的建議!
那'while'循環有'for'循環的語法並且不能編譯。請發佈顯示問題的[Minimal,Complete和Verifiable示例](http://stackoverflow.com/help/mcve)。 –
謝謝,我編輯它 – sworwitz
您的結果不會重現:(...檢查:https://ideone.com/oAWAiw,在這裏我們得到'hello'作爲輸出時輸入'bye' – Cherubim