以下程序的输出结果是()。  #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

相似考题
更多“以下程序的输出结果是()。  #include<std”相关问题
  • 第1题:

    以下程序执行后输出的结果是【】。 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”。

  • 第2题:

    程序的输出结果是【 】。 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。

  • 第3题:

    下列程序的输出结果是【】。 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

  • 第4题:

    下列程序的输出结果是【】。 include using namespace std; int main(){int data=1;int

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

    include <iostream>

    using namespace std;

    int main()

    {

    int data=1;

    int &r = data;

    data+=5;

    r+=5;

    cout<<data<<end 1;

    return 0;

    }


    正确答案:11
    11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后data的值为11。

  • 第5题:

    以下程序的输出结果是【】。 include using namespace std; int main(){ int sum,i; for(

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

    include<iostream>

    using namespace std;

    int main(){

    int sum,i;

    for(sum=0,i=1;i<5;i++)sum+=i;

    cout<<sum<<endl;

    return 0;

    }


    正确答案:10
    10 解析:本题程序实现的是计算1+2+3+4的和,因此最后输出为10。

  • 第6题:

    下面程序运行输出的结果是【】。 include using namespace std; int main(){char a[]="C

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

    include <iostream>

    using namespace std;

    int main(){

    char a[]="Chinese";

    a[3]='\0';

    cout<<a<<endl;

    return 0;

    }


    正确答案:Chi
    Chi 解析:字符串的结束标识是'\0',输出字符串时,到第一个'\0'输出结束,而不管其后是否还有数据,因此本题输出为字符中的前3个字符。

  • 第7题:

    下面程序的执行结果是【】。 include include using namespace std; void main(

    下面程序的执行结果是【 】。

    include<iostream>

    include<iomanip>

    using namespace std;

    void main()

    {

    cout<<setfill('x')<<setw(10);

    cout<<"Hello"<<endl;

    }


    正确答案:xxxxxHello
    xxxxxHello

  • 第8题:

    若有以下程序: include using namespace std; int main() {char str[10];cin>>str;co

    若有以下程序:

    include <iostream>

    using namespace std;

    int main()

    {

    char str[10];

    cin>>str;

    cout<< str<<end1;

    return 0;

    }

    当输入为:

    This is a program!

    那么执行程序后的输出结果是【 】。


    正确答案:This
    This 解析:本题考核C++的标准输入/输出。提取符可以从输入流中读取一个字符序列,即一个字符串。在处理这种字符序列时,字符串被认为是一个以空白字符结束的字符序列。因此,本题得到的输入仅仅是第一个空白符之前的字符序列 This。所以程序最后的输出是This。

  • 第9题:

    下列程序的输出结果是【】includeusing namespace std;int &qetVar(int *pint){ ren

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

    include<iostream>

    using namespace std;

    int &qetVar(int *pint)

    {

    renurn *pint;

    }

    int main ()

    {

    int a =10;

    getVar(&a) = 20;

    cout<<a<<end1;

    return 0; }


    正确答案:20
    20 解析:本题考核引用的使用。题中函数getVar返回的为实参的引用,即将a的引用赋值为20,所以最后输出a的值为20。

  • 第10题:

    若有以下程序: include usingnamespace std; class Sample { private: const int n;

    若有以下程序:

    include <iostream>

    using namespace std;

    class Sample

    {

    private:

    const int n;

    public:

    Sample(int i) :n(i) {)

    void print()

    {

    cout<<"n="<<n<<end1;

    }

    };

    int main()

    {

    sample a(10);

    a.print();

    return 0;

    }

    上述程序运行后的输出结果是【 】。


    正确答案:n=10
    n=10 解析:本题考核常成员数据的应用。类Sample中,定义了一个常数据成员n,所以构造函数只能通过初始化列表来初始化它。

  • 第11题:

    有以下程序: include include using namespace std; int main() {char arr[

    有以下程序: #include<iostream> #include<string> using namespace std; int main() { char arr[2][4]; strcpy(arr[0],"you"); strcpy(arr[1],"me"); arr[0][3]='&'; cout<<arr[0]<<end1; return 0; } 执行后的输出结果是( )。

    A.you&me

    B.you

    C.me

    D.err


    正确答案:A
    解析:本题考核字符串函数的使用。主函数中,首先定义了千个二维字符数组art。语句“strcpy(arr,"you");”中的alt代表二维字符数组的首元素地址,此语句的作用是将字符串“you”复制到arr数组的前4个元素中,第4个元素的值为'\0'。语句“strcpy(arr[1],"me");”的作用是把字符串“me”赋值到arr数组的第2行。语句“arr[0][3]='及';”的作用是用字符'&'取代了原来arr[0][3]中的字符'\0'。所以程序最后输出you&me。

  • 第12题:

    有以下程序:includeincludeusxng namespace std;int main(){ char p[] = "a

    有以下程序: #include <iostream> #include <string> usxng namespace std; int main() { char p[] = "abcdefgh"; cout<<strlen(strcpy(p,"12345"))<<end1; return 0; } 执行后输出的结果是( )。

    A.8

    B.12

    C.5

    D.7


    正确答案:C
    解析:本题考查对字符串函数的熟悉程度。本题主要考查strlen和strcpy两个函数,先来了解这两个函数。①函数strcpy()的函数原型为:char*strcpy(char*strDest,constchar*strSrC);其功能是复制strSrc所有字符到strDest,并返回strDest。②函数strlen()的函数原型为:size_tstrlen(constchar*string);,其功能是返回string的长度,不包括结束字符'\0'。在了解函数的原型和功能后,再分析本程序。程序首先定义了字符数组p,并赋初值"abcdefg",然后将字符串"12345"复制到数组p中,此时数组中元素变为字符串"12345",然后调用函数strlen求出数组p中的字符数为5(不包括结束标志符'\0')。

  • 第13题:

    若有以下程序段: 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指向的字符串。

  • 第14题:

    以下程序的输出结果是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。

  • 第15题:

    以下程序的输出结果是【】。 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。

  • 第16题:

    有以下程序: include using namespace std; int main() {int i=010,j=10;cout<<(++i)

    有以下程序:

    include <iostream>

    using namespace std;

    int main()

    {

    int i=010,j=10;

    cout<<(++i)<<","<<i--<<end1;

    return 0;

    }

    则该程序运行后的输出结果是【 】。


    正确答案:910
    9,10 解析:本题考核自增运算符和自减运算符的使用以及常量的表示形式。程序中i的值是八进制,代表十进制中的8,++i是在语句运算前自身加1,而j--是在语句运算结束后减1。

  • 第17题:

    下列程序的输出结果是______。 include using namespace std; void fun(int &rf) {

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

    include<iostream>

    using namespace std;

    void fun(int &rf)

    {

    rf*=2;

    }

    int main()

    {

    int num=500;

    fun(num);

    cout<<num<<endl;

    return 0;

    }


    正确答案:1000
    1000 解析:本题考核引用作为函数参数的使用。引用作为形参时,它实际上就是实参,函数对形参的访问和修改就是对实参的访问和修改,题中函数fun对形参的操作是自增2倍,所以经过函数调用后,实参的值自增2倍,即输出1000。

  • 第18题:

    下列程序的输出结果是______。 include using namespace std; int main() {int data=l;

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

    include<iostream>

    using namespace std;

    int main()

    {

    int data=l;

    int &r = data;

    data+=5;

    r+=5;

    cout<<data<<endl;

    return 0;

    }


    正确答案:11
    11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后 data的值为11。

  • 第19题:

    有以下程序,其输出结果是()。include using namespace std;int main(){ char a[10]={'

    有以下程序,其输出结果是( )。 #include <iostream> using namespace std; int main(){ char a[10]={'1','2','3','4','5','6','7','8','9',0},*p; int i=8; p=a+i; cout<<p-3<<endl; return 0; }

    A.6789

    B.6

    C.789

    D.'6'


    正确答案:A
    解析:没有下标的数组名是一个指向该数组首元素的指针,本程序实现的功能是将字符“6”及其以后的字符按字符串形式输出。

  • 第20题:

    下列程序输出结果是【】。 include using namespace std; template T fun(

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

    include <iostream>

    using namespace std;

    template <typename T>

    T fun(T a, T b) {return (a<=b)?a:b;}

    int main()

    {

    cout<<fun(3,6)<<','<<fim(3.14F, 6.28F)<<end 1;

    return 0;

    }


    正确答案:33.14
    3,3.14 解析:模板的使用,返回较小值。

  • 第21题:

    以下程序的输出结果是()。include using namespace std;int main(){ int a=1,b; switc

    以下程序的输出结果是( )。 #include <iostream> using namespace std; int main(){ int a=1,b; switch(a){ case 1:b=30; case 2:b=20; case 3:b=10; default:b=0; } cout<<b<<endl; return 0; }

    A.30

    B.20

    C.10

    D.0


    正确答案:D
    解析:由于在case分支的语句后没有出现跳转语句,所以程序将一直执行到switch语句结束。即逐步给变量b赋值30、20、10和0,最后b的值为0。

  • 第22题:

    以下程序的运行结果是【】。 include include using namespace std; void main()

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

    include<iostream>

    include<string>

    using namespace std;

    void main(){

    chara[10]="China",b[]="Chin",c[]="ese";

    cout<<strlen(strcat(strcpy(a,b),c))<<endl;

    }


    正确答案:7
    7 解析:本题主要考查C++中字符串函数的使用。strcpy(s1,s2)将s2的内容赋值到s1中; strcat(s1,s2)连接s1和s2两个字符串;strlen(s)返回字符数组s的长度。因此最后输出的结果是b和c进行连接后的字符串长度,即7。

  • 第23题:

    若有以下程序:includeusing namespace std;int main(){ int a=3; cout<<(a+=a-=a+A)

    若有以下程序: #include <iostream> using namespace std; int main() { int a=3; cout<<(a+=a-=a+A) <<end1; return 0; } 程序执行后的输出结果是( )。

    A.-6

    B.12

    C.0

    D.-12


    正确答案:D
    解析:本题考核运算符的优先级和结合性。根据运算符的优先级和结合性用括号来分出表达式的优先级:a+=(a-=(a*A))。先计算a*a得9,再执行语句:a-=9:得到a=-6,然后执行a+=a得到结果-12。

  • 第24题:

    以下程序输出的结果是()。includeusing namespace std;int main(){int **x,*y,z=10;y=

    以下程序输出的结果是( )。 #include<iostream> using namespace std; int main() { int **x,*y,z=10; y=&z; x=&y; cout<< **x+1<<endl; return 0; }

    A.11

    B.x的地址

    C.y的地址

    D.运行错误


    正确答案:A
    解析:执行语句y=&z;后,指针y指向了变量z。执行语句x=&y;后,指针**x指向z。所以**x的值为z的值10,那么程序最后输出为11。