计算字符串的长度
实现字符串的赋值
将字符串逆序存放
计算字符串所占字节数
第1题:
有以下程序 main() {char s[]={"aeiou"},*ps; ps=s; printf("%c\n",*ps+4); } 程序运行后输出的结果是______。
A.a
B.e
C.u
D.元素s[4]的地址
第2题:
有以下程序: #include<stdio.h> void fun(char**p) { ++P;printf("%s\n",*p);} main() char*a[]={"Morning","Afternoon","Evening","Night"}; fun(A); } 程序的运行结果是( )。
A.Afternoon
B.fternoon
C.Morning
D.oring
第3题:
请编写一个函数int stringLen(char*ps),该函数能计算出字符串ps的长度,函数返回值就是字符串的长度(不包括字符串结束标识号'\0')。本题要求:用指针方式及循环来实现该函数。
注意;部分源程序已存在考生文件夹下的文件PROC6,cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数stringLen()的花括号中填写若干语句。
文件PROC6.cpp的内容如下:
//PROC6.cpp
include<iostream>
using namespace std;
int stringLen(char *);
int main()
{
char str[100],*p;
cout<<"Input your string please!\n";
cin>>str;
p=str;
cout<<"The lenth of your string is "<<stringLen(p)<<end1;
return 0;
}
int stringLen(char *ps)
{
// * * * * *
}
第4题:
若有以下定义,则不能代表字符。的表达式是______。 char s[20]="programming",*ps=s;
A.ps+2
B.s[2]
C.ps[2]
D.ps+=2,*ps
第5题:
以下函数fun的功能是返回str所指字符串中以形参c中字符开头的后续字符串的首地址,例如,str所指字符串为Hello!,c中的字符为e,则函数返回字符串ello!的首地址。若str所指字符串为空或不包含c中的字符,则函数返回NULL,请填空。char *fun(char *str,char c){ int n=0; char *p=str; if(p!=NULL) while(p[n]!=c&&p[n]!=’\0’) n++; if(p[n]==’\0’) return NULL; return();}
第6题:
以下程序的输出结果是( )。 #include<iostream.h> int fun (char*s) { char *p=s; while (*p!='\0,) p++: return (p-s): } void main() { cout<<fun (" ABCDEF ")<<endl: }
A.3
B.6
C.8
D.0
第7题:
Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}void
Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello"); printf(str); }请问
运行Test 函数会有什么样的结果?
第8题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明1]
函数void fun(char*w,char x,int*n)用来在w数组中插入x,w数组中的数已按由小到大顺序存放,n指存储单元中存放数组中数据的个数,插入后数组中的数仍有序。
[C函数1]
void fun(char*W,char x,int*n)
{ int i,P;
p=0;
w[*n]=x;
while(x>w[p]) (1) ;
for(i=*n,i>p;i--)w[i]=(2);
w[p]=x;
++*n;
}
[说明2]
函数void revstr(char*s)将字符串s逆置。例如:字符串“abcde”,经过逆置后变为“edcba”。
[C函数2]
void revstr(char*s)
{ char*p,c;
if(s==NULL)return;
p=(3); /*p指向字符串s的最后一个有效字符*/
while(s<p){ /*交换并移动指针*/
C=*s;
(4)=*p;
(5)=c;
}
}
第9题:
下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?
①void GetMemory(char * p)
{
p = (char * )malloc(100);
}
void TestMemory (void)
{
char *str = NULL;
GetMemory (str);
strcpy(str, "hello world");
prinff(str);
}
② char * GetMemory (void)
{
char p[ ] = "hello world";
return p;
}
void TestMemory (void)
{
char * str = NULL;
str = GetMemory( );
printf(str);
}
③void GetMemory(char * * p, int num)
{
* p = (char * )malloc(num);
}
void TestMemory (void)
{
char * str = NULL;
GetMemory(&str, 100);
strcpy( str, "hello" );
printf(sir);
}
④void TestMemory (void)
{
char *str = (char * )malloe(100);
strepy (str, "hello" );
free ( str );
if(str ! = NULL)
{
strepy( str, "world" );
printf(str);
}
}
第10题:
下列程序中,正确的为______。
A.main() { int *pb=&b; float 1>=15.25; print f("%d\n" ,*pb); }
B.amin() { int a,*pa; a=10; *pa=a; prinffC%d",*pa); }
C.main() { char s[20]; char *ps=&s; scanf("%s",*p); printf("%s",*p); }
D.main() { char str[10]; int *ps=str[0]; str="abcdefg"; printf("%s",*p); }
第11题:
以下程序运行后的输出结果是( ) main() { char s[]="1234", *ps; for(ps=s;ps<s+3;ps++)printf("%c",ps); printf("\n"); }
A.123
B.112123
C.1234
D.乱码
第12题:
nice
verynice
nicegood
verygood
第13题:
有以下结构体说明、变量定义和赋值语句 struct STD { char name[10]; int age; char sex; }s[5],*ps; ps=&s[0]; 则以下scanf函数调用语句中错误引用结构体变量成员的是______。
A.scanf("%s",s[0].name);
B.scanf("%d",&s[0].age);
C.scanf("%c",&(ps->sex));
D.scanf("%d",ps->age);
第14题:
有以下程序 main( ) { char str[ ]="xyz",*ps=str; while(*ps) ps++; for(ps--;ps-str>=0;ps--) puts(ps);} 执行后输出结果是
A.yz xyz
B.z yz
C.z yz xyz
D.x xy xyz
第15题:
若指针ps已正确定义,要使ps指向能够存储8个字符的动态存储单元,以下不正确的语句是( )
A.ps=(char*)malloc(8);
B.ps=(char *)malloc(sizeof(char)* 8);
C.ps=(char*)calloc(8,sizeof(char))
D.ps=8*(char*)malloc(sizeof(char))
第16题:
有以下程序 #include <stdio.h> void fun(char **p) { ++p; printf("%s\n",*p); } main() { char *a[]={"Moming","Afternoon","Evening","Night"}; fun(a); } 程序的运行结果是
A.Afternoon
B.fternoon
C.Morning
D.orning
第17题:
void setmemory(char **p, int num)
{ *p=(char *) malloc(num);}
void test(void)
{ char *str=NULL;
getmemory(&str,100);
strcpy(str,"hello");
printf(str);
}
运行test函数有什么结果?( )
第18题:
有以下程序: main() { char str[]="xyz", *ps=str; while(*ps) ps++; for(ps--;ps-str>=O;ps--) puts(ps); } 执行后的输出结果是( )。
A.yz xyz
B.z yz
C.z yz xyz
D.x xy xyz
第19题:
有以下程序main(){ char str[]="xyz",*ps=str; while(*ps) ps++; for(ps--; ps-str>=0; ps--) puts(ps);} 程序的运行结果是A.yz B.z C.z D.x xyz yz yz xy xyz xyz
第20题:
若有以下程序: #include 〈iostream〉 using namespace std; class sample { private: int i; public: void setvalue(int m) { i=m; } void fun(int m) { i+=m; } void disp() { cout〈〈i〈〈end1; } }; int main() { sample *ps; ps=new sample; ps->setvalue(20); ps->fun(5); ps->disp(); return 0; } 程序运行后,输出的结果是( )。
A.15
B.20
C.25
D.30
第21题:
若有以下定义: char s[20]="programming",*ps=s; 则不能代表字符o的表达式是_______。
A.ps+2
B.s[2]
C.ps[2]
D.ps+=2,*ps
第22题:
有以下程序: #include void fun(char(*p)[6]) { int i; for(i=0;i<4;i++)printf("%c",p[i][i]); printf("\n"); } main( ) { char s[6][6]={"ABCDE","abcde","12345","FGHIJ","fghij","54321"}; fun(s); } 程序的运行结果是( )。
A.Aa1F
B.Ab3I
C.ABCD
D.fghij
第23题:
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;
第24题:
计算字符串的长度
实现字符串的赋值
将字符串逆序存放
计算字符串所占字节数