c++ - What problems can one face on dividing a long long by int? -
what safer method perform division:
long long / int or long long / (long long) int?
on dividing long long int, can there security issues or logical issues?
on dividing long long int, can there security issues or logical issues?
the answer no condition denominator not 0.
from docs:
many binary operators expect operands of arithmetic or enumeration type cause conversions , yield result types in similar way. purpose yield common type, type of result. pattern called usual arithmetic conversions, defined follows:
- if either operand of type
long double, other shall convertedlong double.- otherwise, if either operand
double, other shall converteddouble.- otherwise, if either operand
float, other shall convertedfloat.- otherwise, integral promotions (4.5) shall performed on both operands.
- then, if either operand
unsigned longother shall convertedunsigned long.- otherwise, if 1 operand
long int, otherunsigned int, iflong intcan represent values ofunsigned int,unsigned intshall convertedlong int; otherwise both operands shall convertedunsigned long int.- otherwise, if either operand
long, other shall convertedlong.- otherwise, if either operand
unsigned, other shall convertedunsigned.[note: otherwise, remaining case both operands
int]
so like
int / int => returns int float / float => returns float double /double => returns double int / double => returns double int / float => returns float
Comments
Post a Comment