Given two operands and
, let them be integers:
1 2 3 4 |
int a; int b; printf("Please input two integers \n==>"); scanf("%d %d", &a, &b); |
Addition Operator adds two operands
,
:
1 2 |
sum = a + b; printf("The sum is %d\n", sum); |
Subtraction Operator subtracts the second operand
from the first operand
:
1 2 |
difference = a - b; printf("The difference is %d\n", difference); |
Multiplication Operator multiplies both operands
,
:
1 2 |
product = a * b; printf("The product is %d\n", product); |
Division Operator divides the first operand
(numerator) by the second operand
(denominator):
1 2 |
quotient = a / b; printf("The quotient is %d\n", quotient); |
Modulo Operator returns the remainder after integer division of the first operand
(dividend) by the second operand
(divisor):
1 2 |
s = a % b; printf("a mod b is %d\n", s); |
Increment Operator increases the integer value by one.
1 2 3 4 5 6 |
int a; int b; //pre-increment b = ++a; //post-increment b = a++; |
Decrement Operator decreases the integer value by one.
1 2 3 4 5 6 |
int a; int b; //pre-decrement b = --a; //post-decrement b = a--; |
Cf.
The pre-increment and pre-decrement operators increment (decrement resp.) their operand by 1, and the value of the expression is the resulting incremented (decremented resp.) value. The post-increment and post-decrement operators increase (decrease resp.) the value of their operand by 1, but the value of the expression is the operand’s value prior to the increment (decrement resp.) operation.
Wikipedia on Increment and decrement operators