How "()" works and why

Nicholas Vinson nvinson234@gmail.com
Sun Feb 9 21:14:29 GMT 2025



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

>   
>   
> Alexander and his friends



More information about the Gcc mailing list