第三章单元测试
  1. 引用就是变量的别名,声明引用时必须同时对它初始化。( )

  2. A:错 B:对
    答案:对
  3. this指针是成员函数中的特殊指针,它指向调用成员函数的对象起始地址。( )

  4. A:对 B:错
  5. void fun(int * m,long & n);
    int a;
    long b;
    则以下调用合法的是 ( )

  6. A:fun(&a, b); B:fun(&a, &b); C:fun(*a, &b); D:fun(a, b);
  7. 若Sample类中的一个成员函数说明如下:void set(Sample &a),则Sample &a的含义是 ( )

  8. A:a是类Sample的对象引用,用来作函数set( )的形参 B:指向类Sample的名为a的指针 C:变量Sample与a按位与的结果作为函数set的参数 D:将a的地址赋给变量set
  9. 设有以下函数: void fun(int n,char *s){......} 则下面对函数指针的定义和赋值均正确的是? ( )

  10. A:void (*pf)(int, char); pf=&fun; B:void *pf(); pf=fun; C:void (*pf)(int, char *); pf=&fun; D:void *pf(); *pf=fun;
  11. class card {
    public:
    int s;
    };
    card a;
    card* p;
    we can use _________ to access the member variable s. ( )

  12. A:a(s) B:p.s C:a->s D:p->s
  13. When local variable's name is same as member's name, we can access member using this pointer. ( )

  14. A:错 B:对
  15. #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? ( )

  16. A:25 B:45 C:40 D:35
  17. #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? ( )

  18. A:Executed B:10 C:0 D:Error
  19. #include <stdio.h>
    int main()
    {
    int a = 9;
    int & aref = a;
    a++;
    printf("%d", aref);
    return 0;
    }
    Output?( )

  20. A:9 B:error C:10 D:11

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(2) dxwkbang
返回
顶部