1、1.1在下面的语句中错误的是 。 A、int n=5; int y[n] B、const int n=5; int y[n] C、in n=5; int *py=new int[n]; D、const int n=5; int *py=new int[n] 答:A ,选项中n是变量,int y[n]企图定义一动态数组是不可行的。B选项中n为常量,C、D选项均为用new动态操作内存从而可正确定义可调数组。 1.2在下列函数原型中错误的是 。 A、 int add(int X=3,int y=
2、4,int Z=5)
B、 int add(int x,int y=4,jint z)
C、 int add(int x,int y=4,int z=5)
D、 int add(int x,int y,int z=5)
答:B,带默认参数的缺省定义按从右到左顺序进行,在出现缺省定义后不可以再出现非缺省参数。
2.问答题
2.1下面是一个C程序,改写它,使它采用C++风格的I/O语句。
#include
3、 a,b,c:");
scanf("%d%d%d",&a,&b,&c);
temp=a;
a=b;
b=c;
c=temp;
printf("a=%d b=%d c=%d\n",a,b,c);
}
解: #include
4、出返回类型,C++默认该函数的返回类型为 //int。而本题中无返回值,应为void型。 { int a,b,c; int temp; cout<<"Enter a,b,c:"; //cin,cout,及运算符<<,>>在C语言中是没有的,它们正是 //C++提供得新得输入输出方式。其中cin称为标准输入流,cout是标 cin>>a>>b>>c; //准输出流,它们都是流对象;<<是输出运算符,>>是输入运算符。 temp=a; a=b; b=c; c=temp; cout<






