[英]Can someone explain me this while loop what means?
while (a = b)
;
I know that it will probably not be anything so complex but I don't understand what it will become我知道它可能不会那么复杂,但我不明白它会变成什么
Assuming that a
and b
are variables...假设
a
和b
是变量...
What this says is "Assign the value of b
to a
. If this value is non zero, do the inside of the loop (which is "do nothing"). Continue assigning until a
(post assignment) is zero."这说的是“将
b
的值分配给a
。如果该值不为零,则执行循环内部(即“什么都不做”)。继续分配,直到a
(后分配)为零。”
Theoretically, b
could be changed throughout the program via an interrupt or other source.理论上,可以通过中断或其他来源在整个程序中更改
b
。 It could be mapped to an internal register, for example.例如,它可以映射到内部寄存器。 Note that this is also changing
a
, which could set off a chain of events that makes b
zero, ending the loop.请注意,这也会改变
a
,这可能会引发一系列使b
为零的事件,从而结束循环。
If b
and a
are not changing/are not volatile, this could serve (in a jankey way) as "clear a
, assert that b
is zero."如果
b
和a
没有变化/不是易失性的,这可以(以 jankey 方式)作为“清除a
,断言b
为零”。 If b
is non-zero, the program will hang.如果
b
非零,程序将挂起。
Most likely though, it's meant to be while (a == b);
最有可能的是,它应该是
while (a == b);
, which can be treated as "assert that a is not equal to b, and hang otherwise." ,这可以被视为“断言 a 不等于 b,否则挂起”。
if b=0 then it will not execute.如果 b=0 则不会执行。 Otherwise, it will be an infinite loop.
否则,这将是一个无限循环。 Here, the value of b assigned in a.
这里,b 的值分配在 a 中。 Hope you got it.
希望你明白了。
void stringCAT(char *s1, char *s2)
{
while(*s1 != '\0')
{
s1++;
}
for(; *s1 = *s2; s1++,s2++)
{
;
}
}
The for
loop includes your answer. for
循环包含您的答案。 The middle of for statement is condition like inside a while()
. for 语句的中间条件类似于
while()
。 This for loop runs until *s2= '\\0'
and copies data from s2
to s1
at the same time.这个 for 循环一直运行到
*s2= '\\0'
并同时将数据从s2
复制到s1
。 This is valid for the type of char.这对 char 类型有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.