In C the direction of truncation for / and the sign of the result for % are machine-dependent for negative operands, as is the action taken on overflow or underflow. Can someone give me an example?
That's not really an example. I know two's compliment, I know machines have varying size for int, short int etc. and that padding the left side will make a once negative number positive (although I don't know much more than that) but I don't see the case for all of this in regards to / and %
They are saying that it's up to the people who wrote the compiler to decide which of these is true: 17 % -3 = 2 17 % -3 = -2 If you run code on one machine, the first might be true (most modern compilers), and on some other computer from a different manufacturer and with a compiler which never decided one way or the other, the second might be true (non C99 compliant compiler)
Join our real-time social learning platform and learn together with your friends!