面向对象离线离线作业
浙江大学远程教育学院
《面向对象程序设计》课程作业
713005012007 姓名: 曹明敏 学 号:
年级: 2013 春 学习中心: 杭州
————————————————————————————— 第2章
【2.3】 测试下面的注释(它在C++风格的单行注释中套入了类似于C的注释)是
否有效。
//this is a strange /*way to do a comment*/
此注释有效,单行注释中可以嵌套/*…….*/方式的注释。 【2.4】 以下这个简短的C++程序不可能编译通过,为什么,
#include
using namespace std;
int main()
{int a,b,c;
cout<<"Enter two numbers:";
cin>>a>>b;
c=sum(a,b);
cout<<"sum is:"<题。
(1) 以下两个函数原型是否等价:
float fun(int a,float b,char *c);
float fun(int,float,char * );
这两个函数原型是等价的,因为函数原型中的参数名可以缺省。
(2) 以下两个函数的第一行是否等价:
float fun(int a,float b,char * c);
float fun(int,float,char * );
两个函数的第一行是不等价的,因为这个函数的第一行中必须包
含参数名。
【2.6】 下列语句中错误的是( D )。
A(int *p=new int(10); B(int *p=new int[10];
C(int *p=new int; D(int *p=new int[40](0);
【2.7】 假设已经有定义“const char * const name="chen";”下面的语句中
正确的是( D )。
A. name[3]='a'; B. name="lin";
C. name=new char[5]; D. cout<