第三章单元测试
- 引用就是变量的别名,声明引用时必须同时对它初始化。( )
- this指针是成员函数中的特殊指针,它指向调用成员函数的对象起始地址。( )
- void fun(int * m,long & n);
int a;
long b;
则以下调用合法的是 ( ) - 若Sample类中的一个成员函数说明如下:void set(Sample &a),则Sample &a的含义是 ( )
- 设有以下函数: void fun(int n,char *s){......} 则下面对函数指针的定义和赋值均正确的是? ( )
- class card {
public:
int s;
};
card a;
card* p;
we can use _________ to access the member variable s. ( ) - When local variable's name is same as member's name, we can access member using this pointer. ( )
- #include <stdio.h>
int add(int first, int second)
{
return first + second + 15;
}
int operation(int first, int second, int (*functocall)(int, int))
{
return (*functocall)(first, second);
}
int main()
{
int a;
int (*plus)(int, int) = add;
a = operation(15, 10, plus);
printf("%d", a);
return 0;
}
Output? ( ) - #include <stdio.h>
using namespace std;
class Foo
{
public:
Foo(int i = 0){ _i = i;}
void f()
{
printf("Executed\n");
}
private:
int _i;
};
int main()
{
Foo *p;
p -> f();
}
Output? ( ) - #include <stdio.h>
int main()
{
int a = 9;
int & aref = a;
a++;
printf("%d", aref);
return 0;
}
Output?( )
A:错 B:对
答案:对
A:对 B:错
A:fun(&a, b); B:fun(&a, &b); C:fun(*a, &b); D:fun(a, b);
A:a是类Sample的对象引用,用来作函数set( )的形参 B:指向类Sample的名为a的指针 C:变量Sample与a按位与的结果作为函数set的参数 D:将a的地址赋给变量set
A:void (*pf)(int, char); pf=&fun; B:void *pf(); pf=fun; C:void (*pf)(int, char *); pf=&fun; D:void *pf(); *pf=fun;
A:a(s) B:p.s C:a->s D:p->s
A:错 B:对
A:25 B:45 C:40 D:35
A:Executed B:10 C:0 D:Error
A:9 B:error C:10 D:11
温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!