1) When statements such as
cout << 3.0 + 3 ;
are made, how does one know whether the value passed to cout is an int or a float?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s neither. It’s a double.
3.0has type double, and3is promoted to double for the addition; the result of adding a double to a double is a double. That’s independent of what’s being done with the result.There are a bunch of overloaded shift-left operators for ostreams, and there’s one for an argument of type double on the right-hand side, so that’s the one that’s called:
For what it’s worth, that’s a member function, not a free function.