河南成教 / 面向对象程序设计
2[应用题]
#include
# include
void fun(char *w,int m)
{char s,*p1,*p2;
p1=w;
p2=w m-1;
while(p1<>
{
s=*p1;*p1=*p2;*p2=s;
p1 ;
p2--;
}
}
main()
{
char a[10]="abcdefghi";
char *p=new char[10];
strcpy(p,"student");
cout<<"compare:"<<>
if(strcmp(a,p)==0)
cout<<"a == p"<<>
if(strcmp(a,p)>0)
cout<<"a > p"<<>
if(strcmp(a,p)<0)
cout<<"a < p"<<>
cout<<"before:
";
cout<<><>
cout<<><>
cout<<"call fun"<<>
fun(a,strlen(a));
fun(p,strlen(p));
cout<<"after:
";
cout<<><>
cout<<><>
}
程序运行结果为:
2[应用题]
#include
# include
void fun(char *w,int m)
{char s,*p1,*p2;
p1=w;
p2=w m-1;
while(p1<>
{
s=*p1;*p1=*p2;*p2=s;
p1 ;
p2--;
}
}
main()
{
char a[10]="abcdefghi";
char *p=new char[10];
strcpy(p,"student");
cout<<"compare:"<<>
if(strcmp(a,p)==0)
cout<<"a == p"<<>
if(strcmp(a,p)>0)
cout<<"a > p"<<>
if(strcmp(a,p)<0)
cout<<"a < p"<<>
cout<<"before:
";
cout<<><>
cout<<><>
cout<<"call fun"<<>
fun(a,strlen(a));
fun(p,strlen(p));
cout<<"after:
";
cout<<><>
cout<<><>
}
程序运行结果为:
参考答案:
佳题速递: