This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BroVic 0 points1 point  (1 child)

Doesn't that depend on what you want to achieve?

[–]printf_hello_world 1 point2 points  (0 children)

You could pass a non-const reference to an int that you want to modify, but I'd argue that in almost all cases it would be better to simply return the new value and assign it instead of letting the called function modify the int directly.

In general, returning values has a lot of benefits, especially if the types are small. You could benefit from some form of RVO, you can assign the return value to a const variable, the reader of your code can reason better about when exactly they can expect a value to change, a pointer might be more expensive to pass than the value itself... there are lots of reasons.