1、下面程序的正确输出结果为()class test { public: void print() { cout<<"test"<<endl; } }; int main(void) { test *t = new test(); t->print(); t = NULL; t->print(); return 0; }
A、编译不通过 B、运行时必然出错退出 C、运行时可能出错退出
D、test E、test test F、test 随机信息
2、在小端字节序的机器上执行下列代码的输出为多少?
union UData { unsigned char btVals[4]; unsigned int uiVal; }; UData d; int main(void) { d.uiVal = 0x01020408; unsigned int btSum = (d.btVals[0]<<5)+(d.btVals[1]<<3)+(d.btVals[2]<<1)+(d.btVals[3]<<0); cout<<btSum<<endl; return 0; }3、下列代码的输出为()
class CClassA { public: virtual void Print() { printf("A "); } }; void PrintFunc(CClassA a) { a.Print(); } class CClassB:public CClassA { public: virtual void Print() { printf("B "); } }; void PrintFunc(CClassA *pa) { pa->Print(); } int main(void) { CClassB b; PrintFunc(b); PrintFunc(&b); return 0; }A、A A B、A B C、B A
D、B B E、程序无法通过编译 F、运行后程序异常终止
4、以下关于const 的用法错误的是()
A、 const int a = 10; B、 int func(void) const C、 const int func(void) D、 class A { public: void SetStr(const string& str) { _str = str; } private: string _str; }; E、 class A { public: const string& void GetStr(void)const { return _str; } private: string _str; };5、读下题
class A { public: A(); virtual ~A(); int a; }; class B : public A { public: int b; }; A *a = new B; B* b1 = dynamic_cast<B *>(a); B* b2 = static_cast<B *>(a); B* b3 = reinterpret_cast<B *>(a);假如b1的值为 0X12345678,则b2、b3可能的值为()
A、0X12345678 0X12345674
B、0X12345674 0X12345674
C、0X12345678 0X12345678
D、0X12345674 0X12345678