简体   繁体   English

有人可以解释一下这个while循环是什么意思吗?

[英]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...假设ab是变量...

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."如果ba没有变化/不是易失性的,这可以(以 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.

相关问题 有人可以向我解释这行代码的右侧是什么意思吗? - can someone explain to me what the right side of this line of code means? 有人可以解释一下这意味着什么吗? void(* func)(); - Can Someone Explain what this Means? void (*func)(); 有人可以准确解释一下 C 标准中关于指令的以下定义的含义吗 - Can someone explain me exactly what the below definition means in the C standard about directives 有人可以向我解释这段代码的作用吗? - Can someone explain to me what this code does? 有人可以向我解释这是什么类型的吗? - Can someone explain to me what type of sort this is? 有人可以解释一下这个声明中发生了什么吗? - Can someone explain me what is going on in this statement? 有人可以解释一下 for 循环如何反转数组中的元素吗? - Can someone explain me how the for loop reverses the elements in the array? 有人可以帮我解释一下我的 c 代码有什么问题吗? - Can someone help me to explain what is wrong in my c code? 有人可以解释一下我在使用malloc作为指针时发生了什么 - can someone explain me what is happening here for using malloc for pointer ASM到C - 有人可以解释一下这是什么结构吗? - ASM to C - Can someone explain me what structure this is?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM