direction of division operation on integer in c -


does output of code given below depends on compiler or guaranteed same compilers?

int main() { int i=5; i=i/3; printf("%d\n",i); return 0; } 

yes, behaviour of example well-defined.

however, in case of negative values, less clear. pre-c99, whether integer division rounded towards 0 or towards negative infinity left implementation-defined:

if either operand negative, whether result of / operator largest integer less algebraic quotient or smallest integer greater algebraic quotient implementation-defined

c99 mandates rounding towards zero:

when integers divided, result of / operator algebraic quotient fractional part discarded..


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -