void xstrcpy ( char *t, char *s );
void main(void ) {
char source[ ] = "Sayonara" ;
char target[20] ;
xstrcpy ( target, source ) ;
printf ( "\nsource string = %s", source);
printf ( "\ntarget string = %s", target ) ;
}
void xstrcpy ( char *t, char *s ) {
while ( *s != '\0' ){
*t = *s ;
t++ ; s++ ;
}
*t = '\0' ;
}
此代码给出输出:
source string = Sayonara
target string = Sayonara
但是当我更改char target[20];
为时char target[8];
,它给出:
source string = target string = Sayonara
当我更改char target[20];
为 时char target[4];
,它给出:
source string = nara
target string = Sayonara
当我更改char target[20];
为 时char target[3];
,它给出:
source string = nara
target string = Sayonara
为什么源值发生变化,而目标变为具有字符串大小的数组?