C++程序,比較基礎、簡單

CSDN問答 2022-06-23 16:47:46 阅读数:340

c++程序
class Tuple{public: int * arr; Tuple(){ int a[10]; arr = a; for (int i = 0; i < 10; ++i) { a[i] = 0; } } void input(int i, int v){ arr[i] = v; } void output(int i){ cout << "arr[" << i << "] = " << arr[i] << endl; }};int main(){ Tuple t; t.input(5,10); t.output(5); return 0;}

這個是給arr[i]賦值(input和ouput)
這裏面有一個問題

 void output(int i){ cout << "arr[" << i << "] = " << arr[i] << endl; }這一段如果換成void output(int i){ cout << "arr[" << "] = " << arr[i] << endl; }運行結果會顯示被函數改變的值10為什麼????
版权声明:本文为[CSDN問答]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/174/202206170101519803.html