有一个名为 init.txt 的文件,内容如下:
#define HDY(A,B) A/B
#define PRINT(Y) Printf("y=%d\n",Y)
有以下程序
#include "init.txt"
main( )
{ int a=1,b=2,c=3,d=4,k ;
k =HDY(a+c , b+d) ;
PRINT( k ) ;
}
下面针对该程序的叙述正确的是
A) 编译出错
B) 运行出错
C) 运行结果为 y=0
D) 运行结果为 y=6
第1题:
使用VC6打开考生文件夹下的工程test12_1,此工程包含一个源程序文件test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:
fun (Sample &p) 1 2
fun (Sample *p) 3 4
20 10
源程序文件test12_1清单如下:
include<iostream .h>
class Sample
{
private:
int x,y;
static int z;
public:
Sample(int a,int b){ x=a;y=b; }
void fun(Sample &p);
void fun(Sample *p);
static void print(Sample s);
};
/*************** found ***************/
int z=10;
void Sample::fun(Sample &p)
{
x=p.K;y=p.y;
cout<<"fun(Sample &p)"<<" "<<x<<" "<<y<<endl;
}
void Sample::fun(Sample *p)
{
/************** found **************/
x=p.x; y=p.y;
cout<<"fun(Sample *p) "<<" '<<x<<" "<<y<<endl;
}
void Sample::print (Sample s)
{
/*************** found *****************/
x=20;
cout<<s. x<<" "<<z<<endl;
}
void main()
{
Sample p(1,2),q(3,4);
p. fun(p);
p. fun(&q);
p. print(p);
}
第2题:
下列条件语句中,输出结果与其他语句不同的是( )。
A.if(a)printf("%d n",x); else print[("%d\n",y)
B.if(a=0)pritf("%d n",y); else print[("%d\n",x)
C.if(a!一0)printf("%d n",x); else print[("%a\n",y)
D.if(a=O)print[("%d n",x); else printf("%d\n",y)
第3题:
有一个名为init.txt的文件,内容如下: #define HDY(A,B) A/B #define PRINT(Y) Printf(“y=%dn”,Y) 有以下程序 #include“init.txt” void main() {int a=1,b=2,c=3,d=4,k; k=HDY(a+c,b+d); PRINT(k); } 下面针对该程序的叙述正确的是()。
A.编译有错
B.运行出错
C.运行结果为y=0
D.运行结果为 y=6
第4题:
有如下程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<"print1"<<end1; } void print()const { cout<<"print2"<<end1; } }; int main() { const TestClass a(1,2); a.print(); return 0; } 该程序运行后的输出结果是( )。
A.print1
B.print2
C.print1 print2
D.程序编译时出错
第5题:
有下列程序: #include<stdi0.h> voidmain( ) {intx=1,y=2,z=3; if(x>y) if(y<z)print{("%d",++z); elseprintf("%d",++y); printf(”%d\n”,x++); } 程序的运行结果是( )。
A.331
B.41
C.2
D.1