casting - Implicit type conversion rules in C++ operators -
i want improve knowing when should cast. implicit type conversion rules in c++ when adding, multiplying, etc. example,
int + float = ? int * float = ? float * int = ? int / float = ? float / int = ? int / int = ? int ^ float = ? et cetera...
will look evaluated more precise type? rules differ java? please right me if have worded question inaccurately.
in c++ operators (for pod types) deed on objects of same type. if not same 1 promoted match other. type of result of operation same operands (after conversion).
if either long double other promoted long double if either double other promoted double if either float other promoted float if either long long unsigned int other promoted long long unsigned int if either long long int other promoted long long int if either long unsigned int other promoted long unsigned int if either long int other promoted long int if either unsigned int other promoted unsigned int if either int other promoted int both operands promoted int note. minimum size of operations int. short/char promoted int before operation done.
in expressions int promoted float before operation performed. result of operation float.
int + float => float + float = float int * float => float * float = float float * int => float * float = float int / float => float / float = float float / int => float / float = float int / int = int int ^ float => <compiler error> c++ casting implicit
No comments:
Post a Comment