What is the output of the following code?

#include <stdio.h> int main(void) { printf("%d \n",?45 / 7); printf("%d \n", 45 /-7); printf("%d \n",-45 /-7); printf("%d \n", 45 / 7); return 0; }

Click to view the answer

?6 ?6 6 6

With division, the result will always be negative if the operands have different signs.

Thus, the expression ?45 / 7 produces the same result as the expression 45 / ?7, which is ?6.

If the operands in a division are of the same sign, either positive or negative, the result is always positive.

Thus, 45 / 7 produces the same result as ?45 / ?7, which is 6.

- Arithmetic Operations
- Use Basic Arithmetic Operators and variables
- Use Division And Modulus Operator
- Use Unary Minus Operator
- Variable Types and Typical Value Ranges