有以下程序:include using namespace std;int main ( ){ char s1[10],s2[10]; char*p有以下程序: #include <iostream> using namespace std; int main ( ) { char s1[10],s2[10]; char *p=s1,*q=s2; cin>>s1>>s2; while (*p ! =' \0 ' ) p++; while (*q!='\0') *p++=*q++; *p='\0'; cou

题目
有以下程序:include using namespace std;int main ( ){ char s1[10],s2[10]; char*p

有以下程序: #include <iostream> using namespace std; int main ( ) { char s1[10],s2[10]; char *p=s1,*q=s2; cin>>s1>>s2; while (*p ! =' \0 ' ) p++; while (*q!='\0') *p++=*q++; *p='\0'; cout<<s1<<end1; return 0; }

A.abcd0ghij

B.abcd0ghij0

C.abcd

D.abcdghij


相似考题
更多“有以下程序:#include <iostream>using namespace std;int main ( ){ char s1[10],s2[10]; char*p ”相关问题
  • 第1题:

    下列程序的输出结果是()。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循环中,当不指向数组尾时,将小写字母转换为大写字母!然后将其输出。

  • 第2题:

    有以下程序: 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。

  • 第3题:

    有以下程序: include using namespace std; char *x[]={"First", "Second", "Third"

    有以下程序: #include <iostream> using namespace std; char *x[]={"First", "Second", "Third" }; void f(char *z[ ]) { cout<<*z++<<end1; } int main ( ) { char **y; y=x; f(y); return 0; }

    A.产生语法错误

    B.First

    C.Secpnd

    D.Third


    正确答案:B
    解析:程序首先定义全局指针数组x,并赋初值。在函数f()中,语句“cout*z++end1;”是输出*z指向的字符串,然后指向下一个指针。由于在主函数中,指针y已初始化指向指针数组x,所以执行f(y)后,程序输出指针数组x中的第一个字符串"First"。

  • 第4题:

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

    下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]="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循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

  • 第5题:

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

    若有如下程序: #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; } 上述程序的输出结果是( )。

    A.abcdefgh

    B.0

    C.abcd

    D.efgh


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

  • 第6题:

    有以下程序,其输出结果是()。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”及其以后的字符按字符串形式输出。

  • 第7题:

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

    有以下程序:

    include <fstream>

    include <string>

    using namespace std;

    int main ()

    {

    char ch[] = "The end";

    ofstream outstr( "d:\\put.txt", ios_base: :app);

    for (int i = 0; i < strlen( ch ); i++ )

    outstr.put(ch[i]);

    outstr.close();

    return 0;

    }

    程序实现的功能是【 】。


    正确答案:在文件put.txt的尾部追加写入一串字符
    在文件put.txt的尾部追加写入一串字符 解析:解本题的关键是要了解文件打开模式常量ios_base::app的含义。常量ios base::app表示为添加数据而打开文件(总是在文件尾部写),因此上述程序实现的功能就是在文件尾部写入数组ch中字符串。

  • 第8题:

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

    下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]="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循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

  • 第9题:

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

    有以下程序: #include <iostream> #include <fstream> using namespace std; int main ( ) { ofstream ofile; char ch; ofile.open ("abc.txt"); cin>>ch; while (ch!='#' ) { cin>>ch; ofile.put(ch);

    A.程序编译时出错

    B.abc#

    C.abc

    D.#


    正确答案:C
    解析:本题程序的功能是将从键盘终端输入的内容存储到指定的文件中。

  • 第10题:

    有以下程序: 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。

  • 第11题:

    有下列程序段:include using namespace std;int main() { char b[]= "Hello,you"; b[

    有下列程序段: #include <iostream> using namespace std; int main() { char b[] = "Hello,you"; b[5] = 0; cout<<b<<end1; return 0; } 执行此程序后,得到的输出结果是( )。

    A.Hello,you

    B.Hello0you

    C.Hello

    D.0


    正确答案:C
    解析:本题考核字符数组的特性。本题表面上看起来很简单,其实不然,出题者在题中隐藏了一个陷阱。常见的错误答案是:字符数组b初始化后,得b[5]='',执行“b[5]=0;”后,把0代替b[5]中的','即可。最后输出整个字符串“Hello0you”。下面是正确解答:在C++语言中规定:以字符’0’作为字符串结束标志。语句“b[5]=0;”就相当于语句b[5]='\0',即在数组b的b[5]加上了字符串结束标志,故执行该语句后,数组中存放的内容变为Hello。

  • 第12题:

    有以下程序: include using namespace std; int main() {char a[10] = {'1','2','3',

    有以下程序: #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<<end1; return 0; } 执行程序后的输出结果是( )。

    A.6

    B.6789

    C.'6'

    D.789


    正确答案:B
    解析:本题考核如何引用数组。解此题需要注意的几点是:没有下标的数组名就是一个指向该数组第1个元素的指针;字符'0'~'9'与数字0~9是不相等:a[i]与*(a+i)所指的是同一个数组元素。根据以上几点可知,本程序实现的功能是把字符'6'以及其后面的字符按字符串形式输出。

  • 第13题:

    有如下程序: include using namespace std; int main() { char st

    有如下程序: #include <iostream> using namespace std; int main() { char str[100], *p; cout<<"Please input a string:"; cin>>str; p=str; for (int i=0; *p!='\0'; p++,i++); cout<<i<<endl; return 0; }运行这个程序时,若输入字符串为 abcdefgabcd则输出结果是

    A.7

    B.12

    C.13

    D.100


    正确答案:A
    解析:本题考查的知识点是:默认的输入格式。C++流所识别的输入数据的类型及其默认的输入格式包括:
    short、int、long(signed、unsigned).与整型常量同
    float、double、long double:与浮点数常量同
    char(signed、unsigned):第一个非空白字符
    char*(signed、unsigned):从第一个非空白字符开始到下一个空白字符结束
    void*:无前缀的16进制数
    bool:VC6.0中把0识别为false,其他的值均识别为true
    注意其中空白字符和非空白字符的概念。空白字符是指空格、Tab符、回车换行等无显示的字符,否则就是非空白字符。本题的输入数据类型为char*,因此输入的数据是“从第一个非空白字符开始到下一个空白字符结束”,而输入数据为abcdefg abcd,其中abcdefg后有一个空格(空白字符)。所以输入后str中为字符串"abcdefg”,主函数中接下来for语句的作用是计算字符串p的长度。故最终输出的结果是"abcdefg”的长度7,本题应该选择A。

  • 第14题:

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

  • 第15题:

    有以下程序includeincludeusing namespace std;class base{private:charbas

    有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base() { strcpy(baseName,"Base"); } virtual char*myName() return baseName; } char *className() { return baseName; } }; class Derived: public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName0<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dD) ; retum 0; } 动行后的输出结果为

    A.Derived Base

    B.Base Base

    C.Derived Derived

    D.Base Derived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。main()函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数showPtr中调用的myName函数为派生类的成员函数myName,从而输出Derived。然后输出className,即基类名称Base。

  • 第16题:

    有以下程序include include using namespace std;class base{private:char

    有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为

    A.Derived Base

    B.Base Base

    C.Derived Derived

    D.Base Derived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。main()函数中定义了一个基类对象bb和一个派生类对象dd。从程序,中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数 showPtr中调用的myName函数为派生类的成员函数 myName,从而输出Derived。然后输出className,即基类名称Base。

  • 第17题:

    若有如下程序段: 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和一个长整型指针变量q。首先通过语句“a=(long*)p;”,把p的地址值强制转换为长整型地址值并赋值给小然后执行“q++”,地址值增加了4,执行语句“r=(char*)q;”,把长整型指针变量q的值再强制转换成字符型地址值并赋给r,r的值应为字符串中字符“e”的地址。最后输出r指向的字符串。

  • 第18题:

    若有以下程序: 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。

  • 第19题:

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

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

    include <iostream.h>

    include <cstring.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,sh);

    cout<<Ch;

    return 0;

    }


    正确答案:C
    C 解析:本题考核数组的定义、使用以及函数的调用。fun函数的作用是将字符串str中间的字符赋值给地址传入的变量ch。所以ch的值将被修改为‘C’。

  • 第20题:

    有以下程序:include include using namespace std;class base{private: cha

    有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {

    A.DerivedBase

    B.BaseBase

    C.DerivedDerived

    D.BaseDerived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。主函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出,派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数,所以在函数showPtr中调用的myName函数为派生类的成员函数mySame,从而输出Derived。然后输出className,即基类名称Base。

  • 第21题:

    以下程序的执行结果为【】。 include using namespace std; void overload(int num) {cou

    以下程序的执行结果为【 】。

    include<iostream>

    using namespace std;

    void overload(int num)

    {

    cout<<num<<end1;

    }

    void overload(char ch)

    {

    char c=ch+1;

    cout<<c<<end1;

    }

    int main()

    {

    overload('X');

    return 0;

    }


    正确答案:Y
    Y 解析:本题考核函数重载。在本题中,函数overload()有两次实现。第一次实现中,其形参为int型;第2饮实现中,其形参为char型,所以构成了函数重载。主函数中调用overload()函数时传递的实参为字符'X',所以执行函数的第2次实现。输出Y。

  • 第22题:

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

    有以下程序: #include <iostream> #include <string> using namespace std; int main ( ) { char b1[8] = "abcdefg"; char b2[8],*pb=b1+3; while (--pb>=b1) strcpy (b2, Pb) ; cout<<strlen (b2) <<end1; return 0; } 程序运行后的输出结果是( )。

    A.8

    B.3

    C.1

    D.7


    正确答案:D
    解析:本题考查常用字符串函数的熟悉程度。先来了解程序中的两个字符串函数:①函数strcpy()的函数原型为:char*strcpy(char*strDest,constchar*strSrC);,其功能是复制strSrc所有字符到strDest,并返回strDest。②函数strlen()的函数原型为:sizetstrlen(constchar*string);,其函数功能为:返回string的长度,不包括结束字符'\0'。再看程序:程序首先定义了一个字符数组b1和一个指针pb,并让指针pb指向数组中的b1[3]。由于在while语句中,每次循环都是把指针pb所指向的字符串复制到数组b2中,所以可以不考虑循环的中间过程,直接分析最后一次循环。循环体中的最后一次循环条件是pb==b1,即指针pb指向了数组元素b1[0],此时把指针pb所指向的字符串复制到数组b2中,就相当于把数组b1中的字符串复制到数组b2中。所以最后数组b2中保存的就是数组b1中的字符串,其长度为7(不包括字符串结束符号'\0')。

  • 第23题:

    有以下程序: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')。