用dev c++編譯時,在第三個元素時一直出現3的答案。在Visual Studio 2017時雖然都正常列出元素,但最後會報當掉的結果。怪哉....
- #include <iostream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- void test(int *a){
- int i=0;
-
- char ch;
- do{
- cout<<"Enter a number: ";
-
- cin>>a[i];
- a[i+1] = -1;
- cout<<"a["<<i<<"] is "<<a[i]<<" again?(y/n)";
- i++;
- cin>>ch;
- }while(ch!='n');
- }
-
- int main(){
- int x[] = {9,12,121,888,4,1312,349,-1};
- //test(x);
- int i =0;
- while(x[i] != -1) {
- cout<<"x["<<i<<"] is "<<x[i]<<endl;
- i++;
- };
-
- return 0;
- }
複製代碼 |