赞
踩
题6:阅读以下代码:
- class parent
- {
- public:
- virtual void output();
- };
- void parent::output()
- {
- printf("parent!");
- }
-
- class son : public parent
- {
- public:
- virtual void output();
- };
- void son::output()
- {
- printf("son!");
- }
- son s;
- memset(&s , 0 , sizeof(s));
- parent& p = s;
- p.output();
答案:A:parent! B:son! C:son!parent!
D:没有输出结果,程序运行出错
题8:所谓数据封装就是将一组数据和与这组数据有关操作组装在一起,形成一个实体,这实体也就是()
答案:A:类 B:对象 C:函数体 D:数据块
题10:在32位操作系统gcc编译器环境下,下面程序的运行结果为()
- #include <iostream>
- using namespace std;
- class A {
- public:
- intb;
- charc;
- virtualvoidprint() {
- cout <<"this is father’s fuction! "<< endl;
- }
- };
- class B: A {
- public:
- virtualvoidprint() {
- cout << "this is children’s fuction! "<< endl;
- }
- };
- int main(int argc, char * argv[]) {
- cout << sizeof(A) <<""<< sizeof(B) << endl;
- return0;
- }
答案:A:12 12 B:8 8 C:9 9 D:12 16
解析:A中:4(int)+4(char对齐)+4(A中的虚指针)=12,B中:4(A::int)+4(A::char对齐)+4(B中的虚指针)=12
题8:以下程序的打印结果是()
- #include<iostream>
- using namespace std;
-
- void swap_int(int a , int b)
- {
- int temp = a;
- a = b;
- b = temp;
- }
-
- void swap_str(char*a , char*b)
- {
- char*temp = a;
- a = b;
- b = temp;
- }
-
- int main(void)
- {
- int a = 10;
- int b = 5;
- char*str_a = "hello world";
- char*str_b = "world hello";
- swap_int(a , b);.
- swap_str(str_a , str_b);
- printf("%d %d %s %s\n",a,b,str_a,str_b);
-
- return 0;
- }
答案:
A:10 5 hello world world hello B:10 5 world hello hello world C:10 hello world world hello D:10 hello world world hello
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。