enter 發表於 2019-4-6 19:14:30

一個有點詭異的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;
                a = -1;
                cout<<"a["<<i<<"] is "<<a<<" 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 != -1) {
                cout<<"x["<<i<<"] is "<<x<<endl;
                i++;
        };
       
        return 0;
}
頁: [1]
查看完整版本: 一個有點詭異的C++程式