code.club
標題:
一個有點詭異的C++程式
[打印本頁]
作者:
enter
時間:
2019-4-6 19:14
標題:
一個有點詭異的C++程式
用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;
}
複製代碼
歡迎光臨 code.club (https://code.club/)
Powered by Discuz! X3.2