有如下程序: #include<iostream> using namespace std; class TestClass{ static int i; public: TestClass (){i++;} ~TestClass(){i--;} static int getVal(){return i;} }; int TestClass::i=0; void f(){TestClass obj2;cout<<obj2.getVal();} int main(){ TestClass obj1; f(); TestClass * obj3=new TestClass;cout<<obj3->getVal(); delete obj3;cout<<TestClass::getVal(); return 0; } 程序的输出结果是______。
A. 232
B. 221
C. 222
D. 231
查看答案
下面类的声明中的几个语句,正确的是(设定语句是主函数中的语句)______。 class TestClass { private: int data; public: TestClass(int g_data) { data=g_data; } void show(){cout<<data<<endl;} };
A. TestClass *p;
B. TestClass m;
C. TestClass.data=8;
D. TestClass.show();
有如下程序: #include<iostream> using namespace std; class TlestClass { int n; public: TestClass(int k):n(k){} int get(){return n;} int get()const{return n+1;} }; int main() { TestClass p(5); const TestClass q(6); cout<<p.get()<<q.get(); return 0; } 执行后的输出结果是______。
A. 55
B. 57
C. 75
D. 77
设程序如下: #include<iostream> using namespace std; int main() { int **p,*q,r=10; q=&r; p=&q; cout<<**p+1<<endl; return 0; } 以上程序的输出结果是______。
A. P的地址
B. r的地址
C. 11
D. 运行错误
有如下程序: #include<iostream> using namespace std; class Base{ protected: Base(){cout<<"Base";} Base(char c){cout<<c;} }; class Derived:public Base{ public: Derived(char c){cout<<c;} }; int main(){ Derived d("Derived"); return 0; } 执行这个程序屏幕上将显示输出______。
A. Derived
B. DerivedBase
C. BaseDerived
DerivedDerived