'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



Solution 1:[1]

Assuming that a and b are variables...

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."

Theoretically, b could be changed throughout the program via an interrupt or other source. 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.

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." If b is non-zero, the program will hang.

Most likely though, it's meant to be while (a == b);, which can be treated as "assert that a is not equal to b, and hang otherwise."

Solution 2:[2]

If b=0 then it will not an infinite loop. Otherwise, it will be an infinite loop. Here, the value of b assigned in a. Hope you got it.

Solution 3:[3]

void stringCAT(char *s1, char *s2)
{
    while(*s1 != '\0')
    {
        s1++;
    }

    for(; *s1 = *s2; s1++,s2++)
    {
        ;
    }
}

The for loop includes your answer. The middle of for statement is condition like inside a while(). This for loop runs until *s2= '\0' and copies data from s2 to s1 at the same time. This is valid for the type of char.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yhyrcanus
Solution 2
Solution 3