代码:
#include <iostream>
using namespace std;
int CircleArea(){
double* pd = new double;
if(! pd){
cout <<"error memory allocation !";
return 1;
}
// cout << *pd <<"\n";
double& rd = *pd;
cout << "the radius is:";
cin >> rd;
cout << "the area of circle is "<< rd*rd*3.14 <<endl;
delete &rd;
return 0;
}
int main(){
if (CircleArea()) cout <<"program failed.\n";
else cout <<"program successed.\n";
return 0;
}
测试结果:
0
the radius is:2
the area of circle is 12.56
program successed.