-2
我有一個'char'類型的數組,其中最後一個符號'\ 0'。'char'類型的數組中的最後一個符號C++
#include<iostream>
void main()
{
char a[4];
a[0] = 'r';
a[1] = 'r';
a[2] = 'r';
a[3] = '\0';
for (int i = 0; i < 6; i++)
{
cout << a[i];
}
cout << endl;
}
因此,當我嘗試輸出比此數組多的符號時,它會在'\ 0'符號後面打印隨機符號。
輸出:
rrr ╠╠
我的問題是:如何建立我的陣列後 '\ 0' 符號不符號?
[訪問數組超出範圍不會出現錯誤,爲什麼?](http://stackoverflow.com/questions/1239938/accessing-an-array-out-of-bounds-gives-no-error - 爲什麼) –
你不能。如果你走出界限,你會有*未定義的行爲*。故事結局。 –
你可以。編寫你自己的類CGreatArray。 – KonstantinL