0

I am starter of C++. When I study the opensource, I see the function.

int foo(int a, int b){
    return a=b;
}

But I only know the function return such as...

int foo(int a, int b){
    return a;
}

what is the meaning of this "return a=b" statement?

RIEVER
  • 37
  • 3
  • 4
    _I am starter of C._ Please, don't confuse C with C++. These are two distinct languages (though C++ evolved out of C). There are quite a lot of people in this community who are quite sensitive about this... – Scheff's Cat Aug 01 '21 at 07:33
  • 2
    Btw. while `return a=b;` is valid and working -- it's complete non-sense. The compiler will hopefully eliminate the assignment from the generated code as it has no visible side effect. (`a` and `b` are value parameters. They stop to exist just after the `return`. So, there is no opportunity to do anything with the assigned `a`. `return b;` would result in the exact same outcome.) – Scheff's Cat Aug 01 '21 at 07:36
  • Can you show the context in which you saw this? Also, you say "C" in thr question but your tag and title say "C++". Choose one. – mediocrevegetable1 Aug 01 '21 at 07:39
  • Oh I edited C-> C++. Sorry for the confusion. And I understand the meaning of return a=b. – RIEVER Aug 01 '21 at 07:53
  • 1
    [The Definitive C++ Book Guide and List](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Evg Aug 01 '21 at 08:13

0 Answers0