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 converted long double.
  • otherwise, if either operand double, other shall converted double.
  • otherwise, if either operand float, other shall converted float.
  • otherwise, integral promotions (4.5) shall performed on both operands.
  • then, if either operand unsigned long other shall converted unsigned long.
  • otherwise, if 1 operand long int , other unsigned int, if long int can represent values of unsigned int, unsigned int shall converted long int; otherwise both operands shall converted unsigned long int.
  • otherwise, if either operand long, other shall converted long.
  • otherwise, if either operand unsigned, other shall converted unsigned.

[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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -