int I;
I=0;
while ((CH1[I]=CH2[I]) != '\0')
I++;
puts(CH1);
这个程序是把CH2复制到CH1中,但是我不明白循环条件(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”时立即中断,这意味着已到达字符串末尾并且没有更多字符可供复制。
关于c - 带关系运算符的 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48142386/