网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
有以下函数: int fun(char *ps) {  char *p;  p=ps;  if(*ps==NULL)return 0;  while(*++p);  return(p-ps); } 该函数的功能是(  )。
A

计算字符串的长度

B

实现字符串的赋值

C

将字符串逆序存放

D

计算字符串所占字节数


参考答案

参考解析
解析:
在fun函数中定义了字符指针P,首先把形参ps(相当于字符串的首地址)赋值给指针P,再通过while循环移动p指针,当p指针指向的存储单元的内容为0时,退出while循环,返回此时p地址和ps地址差值,即字符串的长度。答案选择A选项。
更多 “单选题有以下函数: intfun(char*ps) {  char*p;  p=ps;  if(*ps==NULL)return0;  while(*++p);  return(p-ps); } 该函数的功能是(  )。A 计算字符串的长度B 实现字符串的赋值C 将字符串逆序存放D 计算字符串所占字节数” 相关考题
考题 以下函数 fun 的功能是返回 str 所指字符串中以形参 c 中字符开头的后续字符串的首地址 , 例如 : st r所指字符串为 : 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]!=cp[n]!='\0') n++;if(p[n]=='\0') return NULL;return( 【 1 2 】 );}

考题 有以下程序main(){ char s[]={"aeiou"},*ps;ps=s; printf("%c\n",*ps+4);}程序运行后的输出结果是A)aB)eC)uD) 元素 s[4] 的地址

考题 有以下结构体说明、变量定义和赋值语句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);

考题 编写一个函数,从传入的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标志)。注意:部分源程序给出如下.请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:include<conio.h>include<stdio.h>include<string.h>fun(char (*a) [81], int num, char *max){}main (){char ss[l0] [81],*ps;int n, i=0;clrscr();prlntf("输入若干个字符串");gets(ss[i]);puts(ss[i]);while(!strcmp(ss[i], "****")==0)/*用****作为结束输入的标志*/{i++;gets(ss[i]);puts(ss[i]);}n=i;ps=fun(ss,n,ps);print~("\nmax=%s\n",ps);}

考题 有以下程序 main() {char s[]={"aeiou"},*ps; ps=s; printf("%c\n",*ps+4); } 程序运行后输出的结果是______。A.aB.eC.uD.元素s[4]的地址

考题 有以下结构体说明、变量定义和赋值语句 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);

考题 有以下程序:includevoid fun(char**p){++P;printf("%s\n",*p);}main()char*a[]={"Morn 有以下程序: #include<stdio.h> void fun(char**p) { ++P;printf("%s\n",*p);} main() char*a[]={"Morning","Afternoon","Evening","Night"}; fun(A); } 程序的运行结果是( )。A.AfternoonB.fternoonC.MorningD.oring

考题 有以下程序 main( ) { char str[ ]="xyz",*ps=str; while(*ps) ps++; for(ps--;ps-str>=0;ps--) puts(ps);} 执行后输出结果是A.yz xyzB.z yzC.z yz xyzD.x xy xyz

考题 请编写一个函数int stringLen(char*ps),该函数能计算出字符串ps的长度,函数返回值就是字符串的长度(不包括字符串结束标识号'\0')。本题要求:用指针方式及循环来实现该函数。注意;部分源程序已存在考生文件夹下的文件PROC6,cpp中。请勿修改主函数和其他函数中的任何内容,仅在函数stringLen()的花括号中填写若干语句。文件PROC6.cpp的内容如下://PROC6.cppinclude<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){// * * * * *}

考题 若指针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))

考题 若有以下定义,则不能代表字符。的表达式是______。 char s[20]="programming",*ps=s;A.ps+2B.s[2]C.ps[2]D.ps+=2,*ps

考题 有以下程序 include void fun(char **p) { ++p; printf("%s\n",*p); 有以下程序 #include <stdio.h> void fun(char **p) { ++p; printf("%s\n",*p); } main() { char *a[]={"Moming","Afternoon","Evening","Night"}; fun(a); } 程序的运行结果是A.AfternoonB.fternoonC.MorningD.orning

考题 以下函数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]!=cp[n]!=’\0’) n++; if(p[n]==’\0’) return NULL; return();}

考题 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函数有什么结果?( )

考题 以下程序的输出结果是()。includeint fun (char*s){char *p=s;while (*p!='\0,) p++ 以下程序的输出结果是( )。 #include<iostream.h> int fun (char*s) { char *p=s; while (*p!='\0,) p++: return (p-s): } void main() { cout<<fun (" ABCDEF ")<<endl: }A.3B.6C.8D.0

考题 有以下程序: main() { char str[]="xyz", *ps=str; while(*ps) ps++; for(ps--;ps-str>=O;ps--) puts(ps); } 执行后的输出结果是( )。A.yz xyzB.z yzC.z yz xyzD.x xy xyz

考题 Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}voidTest(void){char *str = NULL;GetMemory(str, 100);strcpy(str, "hello"); printf(str); }请问运行Test 函数会有什么样的结果?

考题 有以下程序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

考题 阅读以下函数说明和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;}}

考题 若有以下程序: #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.15B.20C.25D.30

考题 下面的程序各自独立,请问执行下面的四个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);}}

考题 若有以下定义: char s[20]="programming",*ps=s; 则不能代表字符o的表达式是_______。A.ps+2B.s[2]C.ps[2]D.ps+=2,*ps

考题 下列程序中,正确的为______。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); }

考题 有以下程序: include void fun(char(*p)[6]) { int i; for(i=0;i 有以下程序: #include void fun(char(*p)[6]) { int i; for(i=0;iA.Aa1FB.Ab3IC.ABCDD.fghij

考题 以下程序运行后的输出结果是( ) main() { char s[]="1234", *ps; for(ps=s;ps<s+3;ps++)printf("%c",ps); printf("\n"); }A.123B.112123C.1234D.乱码

考题 单选题以下使指针指向一个字符串的选项错误的是(  )。A char str[]=string; char * ps; *ps= str;B char str[]=string; char *ps; ps= str;C char str[]=strinh,* ps=str;D char * ps; ps=str; ps=strinh;

考题 单选题有以下程序:#include main(){ char s[10] = verygood, *ps = s; ps += 4; ps = nice; puts(s);}程序的运行结果是(  )。A niceB veryniceC nicegoodD verygood