include“stdio.h”
void main()
{ char a[]="I am a boy.",b[20],p1,p2;
int i;
p1=a;
p2=b;
for(;p1!='\0';p1++,p2++) p2=p1; /当p1=='\0'时结束循环,因此'\0'并没有复制到p2上/ p2='\0';
printf("string a is:%s\n",a);
printf("string b is:%s\n",b);
printf("\n");
}
方法2
include“stdio.h”
void main()
{ char a="I am a boy.",b;
b=a;
printf("string a is:%s\n",a);
printf("string b is:%s\n",b);
printf("\n");
}
方法1和方法2输出结果都是:
string a is:I am a boy.
String a is:I am a boy.