下列程序的输出结果是 #include <iostream> usingnamespacestd; int main () {chara []="Hello,W

题目
下列程序的输出结果是 include usingnamespacestd; int main () {chara []="Hello,W

下列程序的输出结果是 #include <iostream> using namespace std; int main () { char a [] = "Hello,World": char*ptr = a; while (*ptr) { if(*ptr>= 'a' &&*ptr <='z' cout<<char{*ptr+'A'-'a'); else cout<<*ptr; ptr++; } return 0; }

A. HELLO. WORLD

B. Hello, World

C. hELLO, wORLD

D. hello, world

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

第1题:

下列程序的输出结果是 inClUde using namespace std; intmain() { Char a[]="HellO,W

下列程序的输出结果是

#inClUde<iostream>

using namespace std;

intmain()

{

Char a[]="HellO,World";

Char*ptr=a;

while(*ptr)

{

if(*ptr>='a'&& *ptr <='Z')

cout<<char(*ptr+'A' -'a');

else cout<<*ptr;

ptr++;

}

retur0;

}

A.HELLO,WORLD

B.Hello,world

C.hELLO,wORLD

D.hellO,world


正确答案:A
解析:本题考核while语句和if语句,while语句中if语句的作用是将小写字母变成大写字母输出,所以main函数的字符串通过while语句全部输出为大写字母。

第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 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 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。

第5题:

下列程序的输出结果是______。includeusing namespace std;int main() {char a []="He

下列程序的输出结果是______。 #include<iostream> using namespace std; int main() { char a []="Hello, World"; char *ptr=a; while (* ptr) { if(*ptr)= 'a'&& *ptr' <= 'z') cout << char(*ptr+'A'-'a'); else cout << *ptr; ptr++; } return 0; }

A.HELLO,WORLD

B.Hello,World

C.hELLO, wORLD

D.hello,world


正确答案:A
解析:对于str的每个字母,如果是大写字母或者是非字母,就直接打印出来。如果是小写字母,就转化成大写字母,然后打印。‘A’-‘a’正是大小写字母的ASCII码之差。

第6题:

下列程序的输出结果是()。includeusing namespace std;int main()于chara[]=”Hello,Te

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() 于 chara[]=”Hello,Test”; Char*p=a; while(*p) { if(*p)=’a’&&*p(=’z’) cout<<char(*p+’A’-’a’); else cout<<*p; p++; } return 0; }

A.hello,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST


正确答案:C
解析: 用一个指针变量p指向字符数组a,在while循环中,当不指向数组尾时,将小写字母转换为大写字母!然后将其输出。

第7题:

以下程序的输出结果是【】。 include void main( ) } int a=0; a+=(a=8); cout<

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

include<iostream.h>

void main( )

}

int a=0;

a+=(a=8) ;

cout<<a;

}


正确答案:16
16 解析:赋值表达式的值就是所赋值变量的值,本题中a+=8相当于a=a+8,对表达式逐步进行求解:a+=(a=8)此时,a的值由于赋值为8,而不是o
a+=8
a=a+8
a=16
注意: 要掌握“+=”等相关运算符的用法。

第8题:

下面程序的输出结果为______ include void main() {cout<<"Hello\b"; }

下面程序的输出结果为______

include<iostream.h>

void main()

{

cout<<"Hello\b";

}


正确答案:Hello
Hello

第9题:

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

第10题:

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

更多相关问题