1
字符数组习题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
一、单项选择?/p>
1
?/p>
s12
?/p>
s2
已正确定义并分别指向两个字符串。若要求:当
s1
所指串大于
s2
所指串
时,执行语句
S;
则以下选项中正确的?/p>
_____
A
?/p>
if
?/p>
s1>s2
?/p>
S;
B
?/p>
if
?/p>
strcmp
?/p>
s1,s2
))
S;
C
?/p>
if
?/p>
strcmp
?/p>
s2,s1
?/p>
>0
?/p>
S;
D
?/p>
if
?/p>
strcmp
?/p>
s1,s2
?/p>
>0
?/p>
S;
2.
以下定义语句中,错误的是
________
?/p>
A) int a[]={1,2};
B) char a[]={"test"};
C) char s[10]={"test"};
D) int n=5,a[n];
3
、当接受用户输入的含有空格的字符串时,应使用
______
函数?/p>
A) gets( )
B) getchar( )
C) scanf( )
D) printf( )
4
、设有数组定?/p>
:char array[]="China";
?/p>
strlen(array)
的值为
______
?/p>
A) 4
B) 5
C) 6
D) 7
5
、设有数组定?/p>
:char array[]="China";
则数?/p>
array
所占的存储空间?/p>
________
?/p>
A) 4
个字?/p>
B) 5
个字?/p>
C) 6
个字?/p>
D) 7
个字?/p>
6
、设有数组定?/p>
:char array[10]= "China";
则数?/p>
array
所占的存储空间?/p>
__ _____
?/p>
A) 4
个字?/p>
B) 5
个字?/p>
C) 6
个字?/p>
D) 10
个字?/p>
7.
有如下程?/p>
main()
{ char ch[80];
int j;long s=0;
printf("Enter a numeral string\n");
gets(ch);
for(j=0;ch[j]>'\0';j++)
s=10*s+ch[j]-'0';
printf("%ld\n",s);
}
如果运行时,从键盘上输入由数字组成的字符串,
该程序的功能?/p>
______
?/p>
A)
测字符数?/p>
ch
的长?/p>
B)
将数字字符串
ch
转换成十进制?/p>
C)
将字符数组中的小写字母转换成大写
D)
将字符数组中的大写字母转换成小写
8.
以下程序的输出结果是
______
?/p>
main()
{ char a[10]={'1','2','3',0,'5','6','7','8','9','\0'};
printf("%s\n",a);
}
A) 123
B) 1230
C) 123056789
D) 1230567890
9.
若有定义语句?/p>
char
s[100],d[100]; int j=0,i=0;
,且
s
中已赋字
符串,请在划线处?/p>
______
以实现将字符?/p>
s
中的内容拷贝到字符串
d