(2)形参用字符指针变量 void copy string(from, to) char米from,*to; i for( *from =0, from ++ to++) 米tO=*from 或:将for改用 while while( *from!=0) i*to=*from; to++ from++; 1 c語醒设计
(2) 形参用字符指针变量 void copy_string (from, to) char from, to; { for (; from!='\0 '; from ++, to++) to = from; to = ' \0 '; } 或:将for改用while while (from!= ' \0 ' ) {to= from; to++; from++;}
或:whle(*to=*fom)l=0”){fom++;to+ 或:whle((*to++=米fom++)="O 实际上0的ASCI码为0,故可将 while((*to ++=*from++)=0 简化为:whle(*to++=米from++) c語醒设计
或:while((to = from)!='\0') {from++;to++;} 或:while ( (to++ = from++)!= '\0' ); 实际上'\0'的ASCII码为0,故可将 while ((to ++ = from++)!=0) 简化为: while (to++ = from++)
小结: 字符数组作参数的实、形参调用的四种情况 实参 形参 数组名 数组名 数组名 指针型 指针型 指针型 指针型 数组名 c語醒设计
字符数组作参数的实、形参调用的四种情况 实参 形参 数组名 数组名 数组名 指针型 指针型 指针型…… 指针型 数组名 小结:
、字符数组与字符指针变量 前面介绍中,字符数组与字符指针变量在使用 中具有一定的统一性,但它们之间仍有以下区别: 1.赋值方式不同: 对字符数组只能对各个元素赋值,不可将整个 串赋给数组名, 即: char a[14]; a=" Good Morning!",是错误的 若用指针变量,即可将整个字符串赋给指针名: char *a a="Good Morning! c語醒设计
三、字符数组与字符指针变量 若用指针变量,即可将整个字符串赋给指针名: char a a= "Good Morning! "; 前面介绍中,字符数组与字符指针变量在使用 中具有一定的统一性,但它们之间仍有以下区别: 1. 赋值方式不同: 对字符数组只能对各个元素赋值,不可将整个 串赋给数组名, 即:char a[14]; a ="Good Morning! "; —是错误的