On Sun, 9 Feb 2025 at 21:15, Nicholas Vinson via Gcc <gcc@gcc.gnu.org> wrote: > > > > On 2/9/25 10:38, саша савельев wrote: > > > > To whom it may concern > > > > > > Me and my classmates found strange behaviour of «()» (in C++) on IT lesson, > > but our teacher couldn’t anwer us why it works in this way. After, we had > > tryed to find out by ourselfs, but we found nothing. We understood HOW it > > works, but not WHY. Could you explane it for us? > > > > std::cout << (std::cout.fixed, std::cout.precision(100), acos(-1)); > > This code will call all functions in order (we think any combinations of > > functions will be called in order, so might its behavior is defined), but > > «()» will return only last value (return from acos(-1)). > > What you are describing is not the behavior of '(expression)', but the > behavior of the comma operator > (https://en.wikipedia.org/wiki/Comma_operator).
See also https://en.cppreference.com/w/cpp/language/operator_other#Built-in_comma_operator