int I;
I=0;
while ((CH1[I]=CH2[I]) != '\0')
      I++;
puts(CH1);


该程序是在CH1中复制CH2,但我不了解循环条件(CH1[I]=CH2[I]) != '\0')

最佳答案

while循环条件包含两个部分:

CH1[I]=CH2[I] // this is an assignment that copies character at Ith position in array CH2 into array's CH1 Ith position
(...something...) != '\0' // checks if 'something' is not equal to '\0', the string termination character.


因此,while((CH1[I]=CH2[I]) != '\0')一次将一个字符从CH2复制到CH1,并在复制到'\ 0'时立即中断,这意味着到达字符串末尾且没有其他要复制的字符。

08-07 03:33