下面代码有何错误
void func1()
{
int *pa = NULL;
func2(pa);
delete pa;
}
void func2(int *pb)
{
pb = new int(5);
}
第1题:
有如下程序#include <iostream>using namespace std;class A{public:virtual void func1 (){ cout<<"A1"; }void func2(){ cout<<"A2"; }};class B: public A{public:void func l(){ cout<<"B1"; }void func2(){ cout<<"B2"; }};int main() {A *p=new B;p->func1();p->func2();return 0;}运行此程序,屏幕上将显示输出( )。
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第2题:
已知一个类A,类A有三个公有成员:void f1(int),void f2(int)和int a;定义指向类A成员函数的指针是( )。
A.A*p;
B.int A::*Pc=&A.a;
C.void(A::*pA) ();
D.void(A::*p
第3题:
下面程序编译时发现ma[3]=9错误,其原因是______。
include<iostream.h>
class FunArray
{
int*pa; //指向一个数组空问
int size; //数组元素个数
public:
FunArray(int a[],int thesize):pa(a),size(thesize){}
int Size( ){return size;}
}
};
void main( )
{
int s[]={3,7,2,1,5,4};
FunArray ma(s,sizeof(s)/sizeof(int));
ma[3]=9;
cout<<ma[3]<<endl;
}
第4题:
设有C语言变量说明“static int a[][2]={{1,2),(3,4}};int *pa,(*pb)[2];”,则执行语句“pa=pb=&a[0][0];”后,(*(pa+1))的值为(31)。
A.2
B.3
C.&a[0][1]
D.&a[1][0]
第5题:
有如下程序void func1(int st[],int i){ printf("%c",st[i]); if(i}void func2(int st[],int i){ printf("%c",st[i]); if(i}main(){ char st[ ]="hello,friend! "; int i=0;func1(st,i); printf("\n");}程序执行后输出的结果是A.hello B.hel C.hlo D.编译出错
第6题:
下面程序执行后的结果是( )。 #include<iostream> using namespace std; void func1(int i); void func2(int i); char st[]="hello, friend!"; void func1(int i) { cout<<st[i]; if(i<3){i+=2;func2(i);} } void func2(int i) { cout<<st[i]; if(i<3){i+=2;func1(i);} } void main() { int i=0;func1(i);cout<<endl;}
A.ello
B.hel
C.hlo
D.him
第7题:
下面代码有何错误
void func2(int *value)
{
*value = 2;
}
void func1()
{
int *p = 0;
func2(p);
}
第8题:
C 程序写运行结果。
class A
{
public:
void f1()
{
printf("A::f1\r\n");
}
virtual void f2()
{
printf("A::f2\r\n");
}
void callfunc()
{
printf("A::callfunc\r\n");
f1();
f2();
}
};
class B :public A
{
public:
void f1()
{
printf("B::f1\r\n");
}
void f2()
{
printf("B::f2\r\n");
}
void callfunc()
{
printf("B::callfunc\r\n");
f1();
f2();
}
};
int main()
{
B *pB=new B;
pB->callfunc();
A *pA=pB;
pA->callfunc();
return 0;
}
第9题:
有下列程序void func1(int i);void func2(int i);char st[ ]="hello,friend! ";void func1(int i){ printf("%c",st[i]); if(i<3){i+=2;func2(i);}}void func2(int i){ printf("%c",st[i]); if(i<3){i+=2;func1(i);}}main(){ int i=0;func1(i); printf("\n");}执行后的输出结果是A.hello B.helC.hlo D.hlm
第10题:
对于类定义 class A{ public: virtual void func1( ){} void func2( ){} }; class B:public A{ public: void func1( ){cout<<"class B func 1"< < end1;} virtual void func2( ){cout << "class B func2"<< end1;} }; 下面正确的
A.A::func2( )和B::func1( )都是虚函数
B.A::func2( )和B::func1( )都不是虚函数
C.B::func1( )是虚函数,而A::func2( )不是虚函数
D.B::func1( )不是虚函数,而A::func2( )是虚函数
第11题:
有以下程序: #include 〈iostream〉 using namespace std; class A { public: virtual void setx(int i,int j=0) { x=i; y=j; } virtual void print()=0; protected: int x,y; }; class B : public A { public: void print() { cout〈〈x*x〈〈", "; } }; class C : public A { public: void print() { cout〈〈x*x*x〈〈end1; } }; int main() { A *pa; B b; C c; pa=&b; pa->setx(5); pa->print (); pa=&c; pa->setx(2); pa->print(); return 0; } 程序运行后的输出结果是( )。
A.25,8
B.2,5
C.5,2
D.8,25
第12题:
&pb=a;
pb=pa;
pb=&pa;
?pb=?pa;
第13题:
下列程序执行后的输出结果是______。
A.hello
B.hel
C.hlo
D.hlm void func1 (int i); void func2 (int i); char st[]="hello,friend!"; void func1(int i) { printf("%c",st[i]); if(i<3){ i+=2;func2(i); } } void func2 (int i) { printf("%c",st[i]); if(i<3){ i+=2;func1(i); } } main() { int i=0;func1(i);printf("\n");}
第14题:
下列程序执行后的输出结果是 void funcl(int i); void func2(int i); char st[]="hello,friend!"; void funcl(int i) {printf("%c",st[i]); if(i<3){i+=2;func2(i);}} void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;func1(i);}} main() {int i=
A.hello
B.hel
C.hlo
D.hlm
第15题:
已知一个类Sample,( )是定义指向类Sample成员函数的指针,假设类有三个公有成员:voidfl(int),void f2(int)和int a。
A.Sample*p
B.Int Samale::*pc=&Sample::a
C.Void (Sample::*Pa) ()
D.Sample *P[10]
第16题:
写出下列代码的输出内容
#include
int inc(int a)
{
return(++a);
}
int multi(int*a,int*b,int*c)
{
return(*c=*a**b);
}
typedef int(FUNC1)(int in);
typedef int(FUNC2)(int*,int*,int*);
void show(FUNC2 fun,int arg1, int*arg2)
{
INCp=&inc;
int temp =p(arg1);
fun(&temp,&arg1, arg2);
printf("%d\n",*arg2);
}
main()
{
int a;
show(multi,10,&a);
return 0;
}
第17题:
下列程序执行后的输出结果是( )。 #include<stdio.h> void func1(int i); void func2(int i); char st[]="hello,friend!"; void funcl(int i) { printf("%c",st[i]); if(i<3){i+=2;func 2(i);} } void func 2(int i) { printf("%c",st[i]); if(i<3){i+=2;funcl(i);} } main() { int i=0; funcl(i);printf("\n"); }
A.hello
B.hel
C.hlo
D.hlm
第18题:
下列程序执行后的输出结果是( )。 void func1 (int i); void func2(int i); char st[]="hello,friend!"; void func1 (int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);} } void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;func1(i);}
A.hello
B.hel
C.hol
D.hlm
第19题:
int func1(int& b)
{
return 0;
}
void func2()
{
int bbb = 3;
func1(&bbb);
func1(bbb);
}
func2中有何错误,func1的参数b 的类型是什么。
第20题:
有如下程序: #include<iostream> using namespace std; class A{ public: virtual void func1(){cout<<"A1";} void func2(){cout<<"A2";} }; class B:public A{ public: void func1(){cout<<"B1";} void func2(){cout<<"B2";} }; int main() { A *p=new B; p->func1(); p->func2(); return 0; } 执行该程序,屏幕上将显示输出( )。
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第21题:
下列程序 void func1(int i); void func2(int i) char st[]="hello,friend!"; void funcl(int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);} } void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;funcl(i);} } main() { int i=0;funcl(i);printf("\n");} 执行后的输出结果是( )
A.hello
B.hel
C.hlo
D.hlrn
第22题:
下列程序中,正确的为______。
A.main() { int *pb=&b; float 1>=15.25; print f("%d\n" ,*pb); }
B.amin() { int a,*pa; a=10; *pa=a; prinffC%d",*pa); }
C.main() { char s[20]; char *ps=&s; scanf("%s",*p); printf("%s",*p); }
D.main() { char str[10]; int *ps=str[0]; str="abcdefg"; printf("%s",*p); }
第23题:
有以下变量说明,下面正确的语句是() int a=10,b; int &pa=a,&pb=b;