用指针控制数组范围
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://298452.blog.51cto.com/288452/55198 |
#include <iostream> const int MAX=5; double* fill_array(double* begin,double* end); void show_array(const double ar[],const double* n); void reValue_array(double r,double ar[],const double* n); int main() { using namespace std; double properties[MAX]; const double* size=fill_array(properties,properties+MAX); show_array(properties,size); cout<<"Please enter the double value you want to change.\n"; double value; cin>>value; reValue_array(value,properties,size); show_array(properties,size); return 0; } double* fill_array(double* begin,double* end) { using namespace std; double* pt; //double* temp; double a; //temp=&a; for(pt=begin;pt!=end;pt++) { cout<<"Please enter the value #: \n"; cin>>a; if(!cin) { cin.clear(); while(cin.get()!='\n') continue; cout<<"Bad input,input process terminated.\n"; break; } else if(a<0) break; *pt=a; } return pt; } void show_array(const double ar[],const double* n) { using namespace std; const double* pt; for(pt=ar;pt!=n;pt++) { cout<<"The value of properties #: \n"; cout<<*pt<<endl; } cout<<endl; } void reValue_array(double r,double ar[],const double* n) { using namespace std; double* pt; for(pt=ar;pt!=n;pt++) { *pt=r; } } 本文出自 “lion_pc” 博客,请务必保留此出处http://298452.blog.51cto.com/288452/55198 本文出自 51CTO.COM技术博客 |


lion-pc
博客统计信息
热门文章
最新评论
友情链接