第五周阅读程序一
2015-04-05 14:19
204 查看
(1) 阅读程序,写出程序的运行结果并理解:
预计结果:1,9
50,30
实际结果:
学习总结:与自己阅读的结果相符,该程序主要运用了对象指针,和对象数组的知识点。
(1) 阅读程序,写出程序的运行结果并理解:
#include <iostream> using namespace std; class base { private: int m; public: base() {}; base(int m){this->m=m;} int get(){return m;} void set(int m){this->m=m;} };//base_end int main() { base *ptr; ptr=new base[2]; ptr->set(30); ptr=ptr+1; ptr->set(50); base a[2]= {1,9}; cout<<a[0].get()<<","<<a[1].get()<<endl; cout<<ptr->get()<<","; ptr=ptr-1; cout<<ptr->get()<<endl; delete[] ptr; return 0; }
预计结果:1,9
50,30
实际结果:
学习总结:与自己阅读的结果相符,该程序主要运用了对象指针,和对象数组的知识点。