Search code examples
c++functionreturnvariable-assignment

C++ returning an assignment?


In C++ what does it mean when a function returns an assignment? e.g.

int a = ...;
int b = ...;
int some_function(p)
{
    return a = b;
}

Solution

  • In this case it performs the assignment, then returns b.

    This sort of stuff might get flagged by the compiler as an inadvertent bug, usually you'd mean a == b, so you may need to deal with that. Doing it as a separate line makes it clear it's intentional.