第二章单元测试
- 有关函数重载的正确说法是 ( )
- 使用运算符 . 可以访问名字空间里的函数。( )
- 作用域运算符“::”的功能是 ( )
- 适宜采用inline定义函数情况是 ( )
- 类A有如下成员函数:
int A::fun(double x){return (int) x/2;}
int A::fun(int x){return x*2;}
设a为类A的对象,在主函数中执行语句int s = a.fun(6) + a.fun(2.0)后的s值 ( ) - Which of the following is a valid inline for function foo? ( )
- #include<iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z)
{
return (x + y + z);
}
int main()
{
printf("%d", fun(10));
return 0;
}
Output? ( ) - #include <iostream>
using namespace std;
int fun(int=0, int = 0)
{
return (x+y);
}
int main()
{
printf("%d", fun(5));
return 0;
}
Output? ( ) - Which of the following in Object Oriented Programming is supported by Function overloading and default arguments features of C++. ( )
- #include <iostream>
using namespace std;
namespace T{
class A {
public:
void show() {
printf("Go");
}
};
}
int main(){
T::A obj;
obj.show();
return 0;
}
Output? ( )
A:函数名相同,函数的返回值不同,而与函数的参数和类型无关 B:函数名相同,参数的个数和类型相同 C:函数名相同,但参数的个数不同或参数的类型不同 D:函数名不同,但参数的个数和类型相同
答案:函数名相同,但参数的个数不同或参数的类型不同
A:对 B:错
答案:错
A:标识成员是属于哪个类或哪个命名空间 B:指出作用域的范围的 C:给定作用域的大小的 D:标识作用域的级别的
答案:指出作用域的范围的
A:函数体含有递归语句 B:函数体含有循环语句 C:函数代码少、频繁调用 D:函数代码多、不常调用
答案:函数代码少、频繁调用
A:4 B:13 C:5 D:7
答案:13
A:None of the above B:void foo() inline {} C:inline:void foo() {} D:inline void foo() {}
答案:inline void foo() {}
A:20 B:10 C:0 D:Compiler Error
答案:Compiler Error
A:10 B:0 C:5 D:Compiler Error
答案:5
A:Inheritance B:Polymorphism C:None of the above D:Encapsulation
答案:Polymorphism
A:0 B:No output C:Compilation Error D:Go
答案:Go
温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!