I am kind of newbie in using c++. I have a quick question, probably a dumb question.
streamsize prec = cout.precision(3);
As I understand correctly this declaration works like that: set the cout
precision to 3, but assign the previous precision value to prec
.
Also, simply, we can assign a function result (say a math addition function) to a variable:
int z = addition(3,4);
In the second one, it does the calculation and assigns the results to the variable z
, not the previous value or a default value. Is my understanding correct? What is the difference between them?
What value a function returns depends entirely on that particular function. Most functions simply return a result of their operation.
The state-setting functions in standard library streams (such as precision
) are a bit unusual in their interface of "I set a new value and return the old one," but it's still perfectly valid, as long as the function's behaviour is documented (which it is in their case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With