通过海量题库、编程比赛和实时排名,系统化提升您的编程能力。
第1题
下面是有关C语言字符数组的描述,其中错误的是()。
不可以用赋值语句给字符数组名赋字符串
可以用输入语句把字符串整体输入给字符数组
字符数组中的内容不一定是字符串
字符数组只能存放字符串
第2题
以下叙述中正确的是()。
语句“char str[10]="string!";”和“char str[10]={"string!"};”并不等价
对于字符串常量“string!”,系统已自动在最后加入了'\0'字符,表示字符串结尾
对于一维字符数组,不能使用字符串常量来赋初值
在语句“char str[]="string!";”中,数组str的大小等于字符串的长度
第3题
以下正确的字符串常量是()。
""
'abc'
Olympic Games
"\\\"
第4题
以下能正确定义字符串的语句是()。
char str[]="\0";
char str="kx43";
char str=";
char str[]={'\064'};
第5题
设有以下定义:
char s1[]="0123"; char s2[]={'0','1','2','3'};
则以下叙述正确的是()。
数组s1的长度小于s2的长度
数组s1和s2的长度相同
数组s1的长度大于s2的长度
数组s1和s2完全等价
第6题
以下选项中,合法的是()。
char str3[]={'d', 'e', 'b', 'u', 'g', '\0'}
char str4; str4="hello world";
char name[10]; name="china";
char str1[5]="pass", str2[6]; str2=str1;
第7题
以下能正确进行字符串赋值的语句组是()。
char*ch; ch="abc";
char ch[]={'a', 'b', 'c'};
char ch[3]= "abc";
char ch[4]; ch="abc";
第8题
以下涉及字符串数组、字符指针的程序段,不会产生编译错误的是()。
char*str,name[10]; str="Hello World";
char*str,name[10]; name="Hello World";
char str1[10]="prog.c", str2[10]; str2=str1;
char head_line[]; head_line="== == == == == == =";
第9题
有以下程序:
#include <stdio.h> #include <string.h> main() { char str[12]={'s', 't', 'r', 'I', 'n', 'g'}; printf("%d\n",strlen(str)); }
程序运行后的输出结果是()。
6
7
11
12
第10题
#include <stdio.h> main() { char s[] = "012xy\08s34f4w2"; int i,n = 0; for(i = 0;s[i]!='0';i++) if(s[i]>'0'&& s[i]<='9')n++; printf("%d\n",n); }
0
3
8
第11题
#include <stdio.h> main(){ char s[]={"012xy"}; int i,n=0; for(i=0;s[i]!=0;i++) if(s[i]>='a'&&s[i]<='z')n++; printf("%d\n",n); }
2
5
第12题
#include <stdio.h> main() { char name[10] = {'S','T','R'}; name[2]='#'; name[6]=0; printf("%s\n",name); }
ST#
STR#
STR#0
STR0
第13题
有如下程序:
#include <stdio.h> main() { char name[10] = {'S','T','R','I','N','G'}; name[3]='E'; name[5]=0; printf("%s\n",name); }
STRENG
STRIEG
STREN
STREN0
第14题
#include <stdio.h> main() { int i,j=0; char a[] = "How are you!",b[10]={0}; for(i=0;a[i];i++) if(a[i]==' ') b[j++]=a[i-1]; printf("%s\n",b); }
we
How are you!
ay
we!
第15题
#include <stdio.h> main() { int i,j=0; char a[] = "How are you",b[10]={0}; for(i=0;a[i];i++) if(a[i]==' ') b[j++]=a[i+1]; printf("%s\n",b); }
Hay
How are you
第16题
以下选项中正确的语句组是()。
char s[]; s="BOOK!";
char*s; s={"BOOK!"};
char s[10]; s="BOOK!";
char*s; s="BOOK!";
第17题
以下使指针指向一个字符串的选项错误的是()。
char str[]="string"; char * ps; *ps= str;
char str[]="string"; char *ps; ps= str;
char str[]="strinh",* ps=str;
char * ps; ps=str; ps="strinh";
第18题
下列语句中,正确的是()。
char *s; s = "Olympic";
char s[7]; s= "Olympic";
char *s; s= {"Olympic"};
char s[7]; s= {"Olympic"};
第19题
下面选项中的程序段,没有编译错误的是()。
char*sp, s[10]; sp ="Hello";
chart sp, s[10]; s ="Hello"
char str1[10] ="computer", str2[10]; str2 = str1;
char mark[]; mark="PROGRAM";
第20题
不能用字符串常量对字符数组名进行整体赋值操作
字符串常量"Hello"会被隐含处理成一个无名字符型数组,它有5个 元素
“char str[7] = "string!";”在语法上是合法的,运行也是安全的
“char *str = "Hello";”与“char str[]; str = "Hello";”效果是一样的
第21题
设有如下程序段:
char s[20]= "Bejing",*p; p=s:
则执行p=s;语句后,以下叙述正确的是()。
可以用*p表示s[0]
s数组中元素的个数和p所指字符串长度相等
s和p都是指针变量
数组s中的内容和指针变量p中的内容相等
第22题
设有定义:char *c;以下选项中能够使字符型指针c正确指向一个字符串的是()。
char str[]="string";c=str;
scanf("%s",c);
c=getchar();
*c="string";
第23题
有以下说明语句:
char *s = "'Name\\Address\n";
指针s所指字符串的长度是( )。
17
15
14
说明语句不合法
第24题
若有说明和语句:
char str[]="Hello", *p; p=str;
则此时*(p+5)中的值为()。
'\0'
'o'
'o'的地址
不确定的值
第25题
#include <stdio.h> main() { char s[]="rstuv"; printf("%c\n",*s+2); }
tuv
字符t的ASCII码值
t
出错
第26题
有以下程序
#include <stdio.h> main() { char ch[]="uvwxyz",*pc; pc=ch; printf("%c\n",*(pc+5)); }
z
元素ch[5]的地址
字符y的地址
第27题
有以下程序(注:字符a的ASCII码值为97):
#include <stdio.h> main() { char *s={"abc"}; do { printf("%d",*s%10); ++s; }while(*s); }
abc
789
7890
979899
第28题
#include <stdio.h> main() { char s[10] = "verygood", *ps = s; ps += 4; ps = "nice"; puts(s); }
程序的运行结果是()。
nice
verynice
nicegood
verygood
第29题
#include <stdio.h> int disp(char *str) { while(*str) putchar(*str++); return *str; } main() { printf("%d\n",disp("NAME")); }
NAME0
NAMEE
NAME
NAME\0
第30题
#include <stdio.h> int disp(char *str) { while(*str) putchar(*str++); putchar('#'); return *str; } main() { printf("%d\n",disp("C##123")); }
C##123#0
C##1230
C##0
C##123#\0
第31题
#include<stdio.h> int fun(char *s) { char *p=s; while(*p++!='\0'); return(p-s); } main() { char *p="01234"; printf("%d\n",fun(p)); }
4
第32题
#include <stdio.h> main() { int password; char *p,old_str[10]="wind"; scanf("%d",&password); p = old_str; while(*p) { printf("#%c",*p+password); p++; } }
程序运行时,从键盘输入2<回车>,输出结果是()。
#y#k#p#f
#wi#nd#
xj#oe
#2222#
第33题
#include <stdio.h> main() { char s1[]="programe",s2[]="Language"; char *p1=s1,*p2=s2; int k; for(k=0;k<8;k++) if(*(p1+k)==*(p2+k)) printf("%s ",(p1+k)); }
grame ame e
g a e
programe
无输出字符
第34题
若要求从键盘读入含有空格字符的字符串,应使用函数()。
gets()
getc()
getchar()
scanf()
第35题
设有定义:char s[81];int i=0;,以下不能将一行(不超过80个字符)带有空格的字符串正确读入的语句或语句组是()。
gets(s);
while((s[i++]=getchar())!='\n');s[i]='\0';
scanf("%s",s);
do{ scanf("%c",&s[i]);} while(s[i++]!='\n');s[i]='\0';
第36题
第37题
以下不能将键盘输入的字符串:This is a string<回车>读入到str中的程序段是()。
char str[80]; scanf("%s",str);
char str[80]; int i=0; while((str[i++]=getchar())1='\n'); str[i]=0;
char str[80]; gets(str);
char str[80], *ps=str; do{ scanf("%c",ps); }while(* ps++!='\n'); *(ps)=0;
第38题
有定义语句:
char s[10];
若要从终端给s输入5个字符,错误的输入语句是()。
gets(&s[0]);
scanf("%s",s+1);
scanf("%s",s[1]);
第39题
#include <stdio.h> main() { char a[30],b[30]; scanf("%s",a); gets(b); printf("%s\n%s\n",a,b); }
程序运行时若输入:how are you?I am fine<回车>则输出结果是()。
how are you? <换行>I am fine
how<换行> are you? I am fine
how are you? I am fine
how are you?
第40题
#include <stdio.h> main() { char a,b,c,d; scanf("%c%c",&a,&b); c=getchar();d=getchar(); printf("%c%c%c%c\n",a,b,c,d); }
当执行程序时,按下列方式输入数据(从第一列开始,<CR>代表回车,注意:回车是一个字符)12<CR>34<CR>则输出结果是()。
1234
124
12<CR>3
12<CR>34
第41题
#include <stdio.h> char fun(char *c) { if(*c<='Z'&&*c>='A') *c-='A'-'a'; return *c; } main() { char s[81],*p=s; gets(s); while(*p) { *p=fun(p); putchar(*p); p++; } printf("\n"); }
若运行时从键盘上输入OPEN THE DOOR<回车>,程序的输出结果是()。
OPEN THE DOOR
OPEN tHE dOOR
open the door
Open The Door
第42题
#include <stdio.h> main() { char A,B,C; B='1'; C='A'; for(A=0;A<6;A++) { if(A%2)putchar(B+A); else putchar(C+A); } }
程序运行后输出的结果是()。
1
3D5FBABCDFE
A2C4E6
1123456
第43题
#include <stdio.h> main() { char *p,old_str[10]="wind"; int password; scanf("%d",&password); p = old_str; while(*p) { printf("%c",*p+password); p++; } printf("\n"); }
ykpf
wind
xjoe
2222
第44题
以下选项中有语法错误的是()。
char *str[] = {"guest"};
char str[][10] = {"guest"};
char *str[3]; str[1] = "guest";
char str[3][10]; str[1] = "guest";
第45题
以下语句中存在语法错误的是()。
char ss[6][20];ss[1]="right?";
char ss[][20]={"right?"};
char *ss[6];ss[1]="right?";
char *ss[]={"right?"};
第46题
若有定义:char*ps[]={"aa","bb","cc","dd"};,则以下叙述正确的()。
ps[0]是字符串"aa"
*ps[0]是字符串"aa"的首地址
ps[0]是字符串"aa"的首地址
*ps[0]是字符串"aa"
第47题
若有以下程序段
char str[4][12] = {"aa","bbb","ccccc","d"},*strp[4]; int i; for(i=0;i<4;i++) strp[i]=str[i];
不能正确引用字符串的选项是()。
*strp
str[0]
strp[3]
strp
第48题
#include <stdio.h> main() { char ch[3][5] = {"AAAA","BBBB","CC"}; printf("%s\n",ch[1]); }
AAAA
CC
BBBCC
BBBB
第49题
#include <stdio.h> main() { char b[4][10]; int i; for(i=0;i<4;i++) scanf("%s",b[i]); printf("%s%s%s%s\n",b[0],b[1],b[2],b[3]); }
执行时若输入:Fig flower is red.<回车>则输出结果是()。
Figflowerisred.
Figflowefis red.
Figflower is red.
Fig flower is red.
第50题
#include <stdio.h> main() { char b[3][10],c; int i; for(i=0;i<2;i++)scanf("%s",b[i]); i=0; while((c=getchar())!='\n')b[2][i++]=c; b[2][i] = '\0'; printf("%s%s%s\n",b[0],b[1],b[2]); }
执行时若输入以下字符串:Peach flower is pink.<回车>则输出结果是()。
Peachflower is pink.
Peachfloweris pink.
Peachflowerispink.
Peach flower is pink.
第51题
#include <stdio.h> main() { char b[4][10],c; int i,j; for(i=0;i<4;i++) { j=0; while((c=getchar())!=' '&& c!='\n')b[i][j++]=c; b[i][j] = '\0'; } printf("%s%s%s%s\n",b[0],b[1],b[2],b[3]); }
程序运行时从第一列开始输入: Peach flower is pink.<回车>则输出结果是()。
Peachflowefispink.
Peachflowefis pink.
第52题
#include <stdio.h> #include <string.h> main() { char w[20], a[5][10] = {"abcdef", "ghijkl", "mnopq", "rstuv", "wxyz"}; int i,j; for(i=0;i<5;i++) { j=0; while(a[i][j]!='\0')j++; w[i]=a[i][j-2]; } w[5]='\0'; puts(w); }
agmrw
ekpuy
djotx
flqvz
第53题
#include <stdio.h> main() { char *a[]={"abcd","ef","gh","ijk"}; int i; for(i=0;i<4;i++)printf("%c",*a[i]); }
aegi
dfhk
abcd
abcdefghijk
第54题
#include <stdio.h> #include <string.h> main() { char *mm[4]= {"abcd", "1234", "mnop", "5678"}; char **pm= mm; int i; for(i=0;i<4;i++) printf("%s",pm[i]+i); printf("\n"); }
abcd1234mnop5678
abcd234op8
a2o8
a1m5
第55题
#include <stdio.h> main() { char *s[6]={"ABCD","EFGH","IJKL","MNOP","QRST","UVWX"},**p; int i; p=s; for(i=0;i<4;i++)printf("%s",p[i]); printf("\n"); }
ABCDEFGHIJKLMNOP
ABCDEFGHHKL
ABCD
AEIM
第56题
#include <stdio.h> main() { char c[2][5]={"6938","8254"},*p[2]; int i,j,s=0; for(i=0;i<2;i++) p[i]=c[i]; for(i=0;i<2;i++) for(j=0;p[i][j]>0;j+=2) s=10*s+p[i][j]-'0'; printf("%d\n",s); }
9284
9824
6982
6385
第57题
#include <stdio.h> void fun(char **p) { ++p; printf("%s\n",*p); } main() { char *a[] = {"Morning", "Afternoon", "Evening", "Night"}; fun(a); }
Afternoon
flemoon
Morning
oming
第58题
以下关于字符串的叙述中正确的是()。
C语言中有字符串类型的常量和变量
两个字符串中的字符个数相同时才能进行字符串大小的比较
可以用关系运算符对字符串的大小进行比较
空串比空格打头的字符串小
第59题
若有定义语句char s[10]="1234567\0\0",则strlen(s)的值是()。
9
10
第60题
下列选项中,能够满足“若字符串s1等于字符串s2,则执行ST”要求的是()。
if(strcmp(s2,s1)==0) ST;
if(s1==s2) ST;
if(strcpy(s1,s2)==1) ST;
if((s1-s2)==0) ST;
第61题
字符数组a和b中存储了两个字符串,判断字符串a和b是否相等,应当使用的是()。
if(strcmp(a,b)==0)
if(strcpy(a,b))
if(a==b)
if(a=b)
第62题
若有定义语句
char*s1="OK",*s2="ok";
以下选项中能够输出"OK"的语句是()。
if(strcmp(s1,s2)==0)puts(s1);
if(strcmp(s1,s2)!=0)puts(s2);
if(strcmp(s1,s2)==1)puts(s1);
if(strcmp(s1,s2)!=0)puts(s1);
第63题
若有定义语句:
char str1[] = "string", str2[8], *str3, str4[10] = "string";
库函数strcpy的功能是复制字符串,以下选项中错误的函数调用是()。
strcpy(str3, "HELLO!");
strcpy(str2, "HELLO!");
strcpy(str1, "HELLO!");
strcpy(str4, "HELLO!");
第64题
以下不能将s所指字符串正确复制到t所指存储空间的是()。
while(*t=*s){t++;s++;}
for(i=0;t[j]=s[i];i++);
do{*t++=*s++;}while(*s);
for(i=0,j=0;t[i++]=s[j++];);
第65题
若有以下定义和语句:
char s1[10]="abcd!", *s2="n123\\"; printf("%d%d\n", strlen(s1), strlen(s2));
则输出结果是()。
55
105
107
58
第66题
以下语句的输出结果是()。
printf("%d\n",strlen("\t\"\065\xff\n"));
输出项不合法,无正常输出
第67题
#include <stdio.h> #include <string.h> main() { printf("%d\n",strlen("0\t\nA011\1")); }
第68题
#include<stdio.h> #include<string.h> main() { char a[10]= "abcd"; printf("%d,%d\n",strlen(a),sizeof(a)); }
7,4
4,10
8,8
10,10
第69题
#include <stdio.h> #include <string.h> main() { char str[]={"Hello,Beijing"}; printf("%d,%d\n",strlen(str),sizeof(str)); }
13,13
13,14
13,15
14,15
第70题
#include <stdio.h> #include <string.h> main() { char x[]="STRING"; x[0]=0; x[1]='\0'; x[2]='0'; printf("%d %d\n",sizeof(x),strlen(x)); }
6 1
7 0
6 3
7 1
第71题
#include <stdio.h> #include <string.h> main() { char a[]="THIS", *b="OK"; printf("%d,%d,%d,%d\n", strlen(a), sizeof(a), strlen(b), sizeof(b)); }
4,5,2,4
4,4,2,1
5,5,3,3
4,5,2,3
第72题
#include <stdio.h> #include <string.h> main() { char name[10]="c-book"; char *str=name; printf("%d,%d,%d,%d\n", sizeof(name), strlen(name), sizeof(str), strlen(str)); }
10,6,4,6
11,6,11,6
11,6,1,6
10,7,1,7
第73题
#include <stdio.h> #include <string.h> main() { char name[9]="c##line"; char *str=name; printf("%d,%d,%d,%d\n", sizeof(name), strlen(name), sizeof(str), strlen(str)); }
9,7,4,7
8,6,9,6
8,6,3,6
10,8,5,8
第74题
#include <stdio.h> main() { char *p1 = 0; int *p2 = 0; float *p3 = 0; printf("%d,%d,%d\n", sizeof(p1), sizeof(p2), sizeof(p3)); }
4,4,4
1,4,8
0,0,0
1,2,4
第75题
有以下程序(strcpy为字符串复制函数,strcat为字符串连接函数):
#include <stdio.h> #include <string.h> main() { char a[10] = "abc",b[10] = "012",c[10] = "xyz"; strcpy(a+1,b+2); puts(strcat(a,c+1)); }
a12xyz
12yz
a2yz
bc2yz
第76题
#include <stdio.h> #include <string.h> main() { char a[20]="ab",b[20]="cdef"; int k=0; strcat(a,b); while(a[k]!='\0') { b[k]=a[k]; k++; } puts(b); }
abcdef
cbcdef
cdef
ab
第77题
有以下程序(其中的strstr()函数头部格式为:char *strstr(char*p1,char *p2)确定p2字符串是否在p1中出现,并返回p2第一次出现的字符串首地址):
#include <stdio.h> #include <string.h> char *a="you"; char *b="Welcome you to Beijing!"; main() { char *p; p=strstr(b,a)+strlen(a)+1; printf("%s\n",p); }
to Beijing!
you to Beijing!
Welcome you to Beijing!
Beijing!
第78题
#include <stdio.h> #include <string.h> char *a="you"; char *b="Welcome you to Beijing!"; main() { char *p; p=b; while(*p != *a)p++; p+=strlen(a)+1; printf("%s\n",p); }
第79题
#include <stdio.h> #include <string.h> main() { char s[]="Beijing"; printf("%d\n",strlen(strcpy(s,"China"))); }
第80题
#include<stdio.h> #include<string.h> main() { char w[20],a[5][10]={"abcdef","ghijkl","mnopq","rstuv","wxyz."}; int i; for(i=0;i<5;i++)w[i]=a[i][strlen(a[i])-1]; w[5]='\0'; puts(w); }
flqv.
第81题
有以下函数:
int fun(char *x,char *y) { int n=0; while((*x==*y)&&*x!='\0') { x++; y++: n++; } }
函数的功能是()。
查找x和y所指字符串中是否有'\0'
统计x、y所指字符串最前面连续相同的字符个数
将y所指字符串赋值给x所指存储空间
统计x和y所指字符串中相同的字符个数
第82题
int fun(char *ps) { char *p; p=ps; if(*ps==NULL)return 0; while(*++p); return(p-ps); }
该函数的功能是()。
计算字符串的长度
实现字符串的赋值
将字符串逆序存放
计算字符串所占字节数
第83题
有以下函数
int aaa(char *s) { char *t=s; while(*t++); t--; return (t-s); }
以下关于aaa函数功能叙述正确的是()。
求字符串s的长度
比较两个串的大小
将串s复制到串t
求字符串s所占字节数
第84题
int fun(char *s) { char *t=s; while(*t++); return(t-s); }
计算s所指字符串占用内存字节的个数
比较两个字符串的大小
计算s所指字符串的长度
将s所指字符串复制到字符串t中
第85题
void fun(char*p,char*q) { while((*p++=*q++)!='\0'); }
实现字符串的复制
第86题
下列函数的功能是()。
fun(char * a,char * b) { while((*b= *a)!='\0') { a++; b++; } }
将a所指字符串赋给b所指空间
使指针b指向a所指字符串
将a所指字符串和b所指字符串进行比较
检查a和b所指字符串中是否有'\0'
第87题
int fun(char *s,char *t) { while((*s)&&(*t)&&(*t++==*s++)); return (*s-*t); }
求字符串的长度
将字符串s复制到字符串t中
连接字符串s和字符串t
第88题
#include <stdio.h> #include <string.h> main() { int i; char a[]="How are you!"; for(i=0;a[i];i++) { if(a[i]==' ') { strcpy(a,&a[i+1]); i=0; } } printf("%s\n",a); }
you!
Howareyou!
areyou!
are you!
第89题
#include <stdio.h> #include <string.h> main() { char a[5][10]= {"china", "beijing", "you", "tiananmen", "welcome"}; int i,j; char t[10]; for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(strcmp(a[i],a[j])>0) { strcpy(t,a[i]); strcpy(a[i],a[j]); strcpy(a[j],t); } puts(a[3]); }
beijing
china
welcome
tiananmen
第90题
有以下程序(strcat函数用以连接两个字符串):
#include <stdio.h> #include <string.h> main() { char a[20]="ABCD\0EFG\0", b[]="IJK"; strcat(a,b); printf("%s\n",a); }
ABCDE\0FG\0IJK
ABCDIJK
IJK
EFGIJK
第91题
有以下程序(程序中库函数islower(ch)用以判断ch中的字符是否为小写字母):
#include <stdio.h> #include <ctype.h> void fun(char *p) { int i=0; while(p[i]) { if(p[i]==' '&&islower(p[i-1]))p[i-1]=p[i-1]-'a'+'A'; i++; } } main() { char s1[100]="ab cd EFG!"; fun(s1); printf("%s\n",s1); }
程序运行后的输出结果是( )。
ab cd EFG!
Ab Cd EFg!
aB cD EFG!
ab cd EFg!
第92题
#include <stdio.h> #include <string.h> main() { char str[][20]={"One*World","One*Dream!"}, *p=str[1]; printf("%d,",strlen(p)); printf("%s\n",p); }
9,One*World
9,One*Dream!
10,One*Dream!
10,One*World
第93题
#include <stdio.h> #include <string.h> main() { char p[20]= {'a','b','c','d'}, q[]="abc", r[]="abcde"; strcat(p,r); strcpy(p+strlen(q),q); printf("%d\n",strlen(p)); }
选择题(1 - 93题,共计100分)