c语言第讲指针与字符串字符数组.pptxVIP

  • 6
  • 0
  • 约5.82千字
  • 约 17页
  • 2020-02-06 发布于上海
  • 举报
a a b b c d e d e f\0 f str[0]2000H str[1]2001H str[2]2002H2003H2004H2005H2006H例1:输出字符串 #includestdio.h void main() { char s[ ]=“computer”, *ps=s ; while(*ps!=‘\0’) { putchar(*ps); ps++; } }printf(“%s”,ps);或: puts(ps)例2:在输入的字符串中删除指定的字符str main( ){ char str[80], *p, ch; int i=0; p=str; gets(p); ch=getchar(); for( ; *p!=‘\0’;p++) if(*p!=ch) str[i++]=*p; str[i]=‘\0’; printf(“The new string is:%s\n”,str); }chci0· · ·str2000H\0运行程序: abcdef c p2000HThe new string is: abdef▲字符指针(变量)与字符数组的区别字符指针与字符数组:两者均可存储和运算字符串。主要区别: ① 存储格式不同: 字符指针变量中存放的是字符串的首地址(2字节);而字符数组中存放的是整个字符串(一个数组元素存放一个字符)。 ② 性质不同:字符

文档评论(0)

1亿VIP精品文档

相关文档