![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
求问一道C++题目
chars[]="Thisiskool!";char*p=s;inti=0;while(*p){*p=*(p+i);i++;if(*p!='')p++;}cout<<s<...
char s[] = "This is kool!";
char *p = s;
int i = 0;
while(*p){
*p = *(p+i);
i++;
if(*p != ' ') p++;
}
cout << s << ' ' << p << endl;
输出结果是 : Thisiskool!
while循环那段没看懂,i在里面有意义吗??
还有最后的输出 cout << s << ' ' << p << endl; s和p不重复吗?? p前面怎么也没有那个符号*了??
新手入门,请多多指教
谢谢了
我运行的结果为什么是 "Tiiko!" 呢?? 展开
char *p = s;
int i = 0;
while(*p){
*p = *(p+i);
i++;
if(*p != ' ') p++;
}
cout << s << ' ' << p << endl;
输出结果是 : Thisiskool!
while循环那段没看懂,i在里面有意义吗??
还有最后的输出 cout << s << ' ' << p << endl; s和p不重复吗?? p前面怎么也没有那个符号*了??
新手入门,请多多指教
谢谢了
我运行的结果为什么是 "Tiiko!" 呢?? 展开
3个回答
展开全部
不是吧,我运行出来是这样的
Tiiko!汤堾
Press any key to continue
吧“!”去掉,你的是中文符号
#include<iostream.h>
void main(){
char s[] = "This is kool";
char *p = s;
int i = 0;
while(*p){
*p = *(p+i);
i++;
if(*p != ' ') p++;
}
cout << s << ' ' << p << endl;
}
运行出来:
Tiiko
Tiiko!汤堾
Press any key to continue
吧“!”去掉,你的是中文符号
#include<iostream.h>
void main(){
char s[] = "This is kool";
char *p = s;
int i = 0;
while(*p){
*p = *(p+i);
i++;
if(*p != ' ') p++;
}
cout << s << ' ' << p << endl;
}
运行出来:
Tiiko
展开全部
在while循环里按F9加断点,然后按F5单步运行,自己分析下就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
while的循环是在复制字符串,并去掉空格。但我认为程序中有问题,p++;if(*p==' ') i++;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询