这个问题如何解决?
											这段代码在编译器中输入:3.4 5.6 p
编译器输出结果为:
fil_array:2
show_array:44 2 5 67
show_array1:4.9007e-317 4.88941e-317
为什么程序跳过了show_array1()函数中的输入环节?在
cout<<p[j]<<' ';
这行就输出了4.9007e-317 4.88941e-317这两个奇怪的数字?
如何修改?代码如下:
程序代码:#include<iostream>
using namespace std;
int fill_array(double ar[],int size){
    int i,count;
    count=0;
    i=0;
    while(cin>>ar[i]&&i<size){
        count++;
        i++;
    }
    return count;
}
void show_array(double ar[],int size){
    cout<<"show_array:";
    for(int i=0;i<4;i++)
        cout<<ar[i]<<' ';
}
double *show_array1(){
    double *b=new double[5];
    for(int i=0;i<5;i++){
        if(!(cin>>b[i]))
            break;
    }
    return b;
}
int main(void){
    double b[8];
    int a=fill_array(b,8);
    cout<<"fil_array:"<<a<<endl;
    
    double c[4]={44,2,5,67};
    show_array(c,4);
    cout<<endl;
    
    double *p=show_array1();
    cout<<"show_array1:";
    for(int j=0;j<=sizeof(p)/sizeof(*p);j++)
        cout<<p[j]<<' ';
    delete [] p;
        
    return 0;
}[此贴子已经被作者于2020-11-30 22:50编辑过]



											
	    

	