工学

单选题语句cout<<(3<<3)<< endl;的输出结果是()A 24B 12C 9D 6

题目
单选题
语句cout<<(3<<3)<< endl;的输出结果是()
A

24

B

12

C

9

D

6

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

有如下程序:includeusing namespace std;class test{private: int a;public: test(

有如下程序:#include<iostream>using namespace std;class test{private: int a;public: test(){cout<<"constructor"<<endl;} test(int a){cout<<a<<endl;} test(const test&_test) { a=_test.a; cout<<"copy constructor"<<en+dl; } ~test(){cout<<"destructor"<<endl;}};int main(){ test A(3); rerun 0;}运行时输出的结果是

A.3

B.constructor destructor

C.copy constructor destructor

D.3 destructor


正确答案:D
解析:本题考查的知识点是:构造函数和析构函数。一个类可以有多个构造函数,但只能有一个析构函数。每一个对象在被创建的时候,都会隐含调用众多构造函数中的一个,而在被销毁的时候,又会隐含调用唯一的那个析构函数。因此,解此类题目只要找准创建时调用的是哪个构造函数,和对象何时被销毁即可。本题只有主函数中创建了一个对象A,并使用了构造参数3,因此会隐含调用test(int a)这个构造函数,输出一个3。接下来主函数结束,对象A被销毁,所以又隐含调用~test()析构函数,输出一个destructor。故本题应该选择D。

第2题:

已知数组arr的定义如下: intarr[5]={1,2,3,4,5};下列语句中输出结果不是2的是( )。

A.cout<<*arr+1<<endl;

B.COUt<<*(art+1)<<endl;

C.cout<<arr[1]<<endl;

D.COUt<<*arr<<endl:


正确答案:D
D。【解析】本题主要考查指针的特殊含义。例*px+1指取px所指对象内容加1,*(px+1)指px指针加1,并取结果指针内容而*px则指px的首元素。

第3题:

( 27 )有如下程序:

#include

using namespace std;

class test {

private:

int a;

public:

test () {cout<< ” constructor ” <<ENDL;}

test ( int a ) {cout<<A<<ENDL;}

test ( const test & _test )

{

a=_testa;

cout<< ” copy constructor ” <<ENDL;

}

test () {cout<< ” destructor ” <<ENDL;}

};

int main ()

}

test A ( 3 )

return0;

运行时输出的结果是

A ) 3

B ) constructor

destruclor

C ) copy constructor

dstructor

D ) 3

destruclor


正确答案:D

第4题:

下列程序的输出结果是【】。 include void main() { int i(1),j(2),k(3),a(10); if(!i

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

include<iostream.h>

void main()

{

int i(1),j(2),k(3),a(10);

if(!i)

a--;

else if(j)

if(k)a=5;

else

a=6;

a++;

cout<<a<<endl;

if(i<j)

if(i!=3)

if(!k)

a=1;

else if(k)

a=5;

6+=2;

cout<<a<<endl;


正确答案:6 7
6 7

第5题:

已知数组arr的定义如下: int arr[5]={1,2,3,4,5}; 下列语句中,输出结果不是2的是

A.cout<<*arr+1<<endl;

B.tout<<*(arr+1)<<endl;

C.cout<<arr[1]<<endl;

D.eout<<%arr<<endl;


正确答案:D
解析:D打印的是指针的地址。

第6题:

语句cout<<setiosflagags(ios::showpos)<<125<<"/t"<<-125<<endl;的输出结果为【 】。


正确答案:×
0

第7题:

下面程序运行输出的结果是【】。 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个字符。

第8题:

( 20 )已知数组 arr 的定义如下:

int arr[5] = {1,2,3,4,5};

下列语句中输出结果不是 2 的是

A ) cout << *arr+1 <<endl;

B ) cout << *(arr+1)<<endl;

C ) cout << arr[1] <<endl;

D ) cout << *arr <<endl;


正确答案:D

第9题:

若有如下变量定义和函数调用语句: inta=5; fun(&A) ; 则执行下面函数后正确的输出结果是( )。 void fun(int*x) { cout<<++*x<<endl; }

A.3

B.4

C.5

D.6


正确答案:D
解析: fun函数中的x参数为整型指针变量。调用fun函数,&a是取a的地址,即将实际参数a的地址传递。函数fun中的*x是变量x所指的存储单元即值5。*运算符的等级高于++,所以先取值5然后加1输出,即为6。

第10题:

以下三条输出语句分别输出什么?

char str1[] = "abc";

char str2[] = "abc";

const char str3[] = "abc";

const char str4[] = "abc";

const char* str5 = "abc";

const char* str6 = "abc";

cout << boolalpha << ( str1==str2 ) << endl; // 输出什么?

cout << boolalpha << ( str3==str4 ) << endl; // 输出什么?

cout << boolalpha << ( str5==str6 ) << endl; // 输出什么?


正确答案:
 

更多相关问题