计算机信息管理(专科)

以下程序的输出结果是()。  #include  void main( )  {float x=3.6;    int  i;   i=(int)x;   printf("x=%f,i=%d/n",x,i); } A、x=3 i=3.600000B、x=3.600000,i=4C、x=3,i=3D、x=3.600000,i=3

题目

以下程序的输出结果是()。  #include  void main( )  {float x=3.6;    int  i;   i=(int)x;   printf("x=%f,i=%d/n",x,i); } 

  • A、x=3 i=3.600000
  • B、x=3.600000,i=4
  • C、x=3,i=3
  • D、x=3.600000,i=3
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序运行后输出的结果是【】。 include using namespace std; class example{ const

下面程序运行后输出的结果是【 】。

include <iostream>

using namespace std;

class example{

const int m;

public:

example(int i):m(i){}

void pr(){cout<<"m="<<m<<endl'}

};

int main(){

example x(100);

x.pr();

return 0;

}


正确答案:m=100
m=100 解析:在类example中,定义了一个常数据成员m,所以构造函数只能通过初始化列表来初始化它。

第2题:

以下程序执行后输出的结果是【】。 include include using namespace std; int

以下程序执行后输出的结果是【 】。

include<iostream>

include<fstream>

using namespace std;

int main(){

ofstream ofile("D:\\temp.txt");

if(!ofile){

cout<<"temp.txt cannot open"<<endl;

return 0;

}

ofile<<"This is a book" <<" " <<54321<<endl;

ofile.close();

ifstream ifile("D:\\temp.txt");

if(!ifile){

cout<<"temp.txt cannot open" <<endl;

return 0;

}

charstr[40];

ifile >> str;

ifile.close();

cout<<Str<<endl;

return 1;

}


正确答案:This
This 解析:程序中利用对象ofile在文件temp.txt中写入“This is a book 54321”。然后利用对象 ifile打开文件,将其中的数据输入到变量str中,由于读时遇到空格就终止,所以str中存放的字符串为“This”。

第3题:

以下程序的输出结果是【】。 include using namespace std; int main() {char S[]="abcde

以下程序的输出结果是【 】。

include <iostream>

using namespace std;

int main()

{

char S[ ]="abcdef";

s[3]='\0';

cout<<s<<end1;

return 0;

}


正确答案:abc
abc 解析:字符串的结束标记是'\0',当输出一个存放在字符数组中的字符串时,只需输出到'\0'为止,而不管其后还有什么数据。本题给字符数组s的元素s[3]赋值'\0',故只能输出3个字符“abc”。

第4题:

下列程序的输出结果是【】。 inClude rsing namespace std; template T fun(

下列程序的输出结果是【 】。

inClude<iostream>

rsing namespace std;

template<typename T>

T fun(Ta,Tb){retum(a<=b)?a:b;)

int main()

{

cout<<fun(3,6)<<','<<fun(3.14F,6.28F)<<endl; .

return 0;

}


正确答案:33.14
3,3.14

第5题:

程序的输出结果是【 】。 include using namespace std; class A{ int x; public: A(int

程序的输出结果是【 】。

include <iostream>

using namespace std;

class A{

int x;

public:

A(int x=1):x(x){cout<<x;}

};

void main(){

A a,b(2),c(3);

}


正确答案:123
123 解析:a对象使用和默认的构造函数,b对象使用2来初始化对象c对象使用3来初始化对象,输出相应的值后,结果变为123。

第6题:

以下程序运行后的输出结果是【】。 include using namespace std; int main() {int i=10,

以下程序运行后的输出结果是【 】。

include<iostream>

using namespace std;

int main()

{

int i=10,i:0;

do{

j=j+i;

i--;

}while(i>2);

cout<<j<<end1;

return 0;

}


正确答案:52
52 解析:do-while语句的特点:先执行循环体,后判断条件。第1次循环执行后,j和i的值分别为10和9。判断循环条件为真,继续执行循环体,j和i分别为19和8。继续上述执行过程,直到i的值为2时,表达式“2>2”不再成立,退出循环。此时j的值为52。

第7题:

若有以下程序段: include using namespace std; int main() {char*p="abcdefgh",*r;l

若有以下程序段:

include <iostream>

using namespace std;

int main()

{

char*p="abcdefgh",*r;

long*q;

q=(long*)p;q++;

r=(char*)q;

cout<<r<<end1;

return 0;

}

该程序的输出结果是【 】。


正确答案:efgh
efgh 解析:本题定义了一个字符型指针变量p,并通过赋初值让它指向了一个字符串,还定义了另一个字符型指针变量r和一个长整型指针变量qo首先通过语句“a=(long*)p;”,把p的地址值强制转换为长整型地址值并赋值给q,然后执行“q++;”,地址值增加了4,执行语句“F(char*)q;”,把长整型指针变量q的值再强制转换成字符型地址值并赋给r,r的值应为字符串中字符“e”的地址。最后输出r指向的字符串。

第8题:

下列程序的输出结果是______。 include include using namespace std; voi

下列程序的输出结果是______。

include<iostream.h>

include<string.h>

using namespace std;

void fun(const char*s,char &C) {c=s[strlen(s)/2];}

int main()

{

char str[]="ABCDE";

char ch=str[1];

fun(str,ch);

cout<<ch;

return 0;

}


正确答案:C
C

第9题:

以下程序的输出结果是includeusing nameSpace std;int main(){ cout.fill('*'); cout

以下程序的输出结果是 #include<iostream> using nameSpace std; int main() { cout.fill('*'); cout.width(5); cout<<hex<<100<<end1; return 0; }

A.**100

B.***64

C.100**

D.64***


正确答案:B
解析:本题考核格式控制数据的输入输出。语句“cout.fill('*');”是将填充字符设置成'*',在输出数据时,如果数据宽度小于设置的宽度,则空闲位置要用'*'填满,语句“cout.width(5);”是将数据的输出宽度设置成5,关键字hex的作用是将整数按十六进制输出,即输出64,又由于初始状态为右对齐,所以程序最终输出***64。

第10题:

以下程序的输出结果是【】。 include using namespace std; void fun() {static int a=0

以下程序的输出结果是【 】。

include <iostream>

using namespace std;

void fun()

{

static int a=0;

a+=2;

cout<<a;

}

int main()

{

int CC;

for(CC=1;cc<4;CC++)

fun();

cout<<end1;

return 0;

}


正确答案:246
246 解析:本题考核函数调用和静态变量。在主函数中通过一个for循环调用了3次fun()函数。第1次调用fun()函数时,a的初始值为0,执行语句“a+=2;”后, a的值为2,输出2;第2次调用时,a的初始值为2,执行语句“a+=2;”后,a的值为4,最后输出4:第3次调用时,a的初始值为4,执行语句“a+=2:”后,a的值为6,最后输出6。

更多相关问题