Arithmetic Operators
The primary arithmetic operators and their corresponding symbols in C are:
Multiplication *
Division /
Modulus %
Addition +
Subtraction –
When the / operator is used to perform integer division the resulting integer
is obtained by discarding (or truncating) the fractional part of the actual
The primary arithmetic operators and their corresponding symbols in C are:
Multiplication *
Division /
Modulus %
Addition +
Subtraction –
When the / operator is used to perform integer division the resulting integer
is obtained by discarding (or truncating) the fractional part of the actual
floating point value. For example:
1/2 = 0
3/2 = 1
The modulus operator % only works with integer operands.
The expression a % b is read as “a modulus b” and evaluates to the remainder obtained after dividing
a by b. For example:
7 % 2 1
12 % 3 0
Increment or Decrement operators
In C, specialized operators have been set aside for the incrementing and decrementing of integer variables. The increment and decrement operators are ++ and -- respectively.
These operators allow a form of shorthand in C:
++i; is equivalent to i=i+1;
--i; is equivalent to i=i-1;
The above example shows the prefix form of the increment/decrement operators. They can also be used in postfix form, as follows:
i++; is equivalent to i=i+1;
i--; is equivalent to i=i-1;
1/2 = 0
3/2 = 1
The modulus operator % only works with integer operands.
The expression a % b is read as “a modulus b” and evaluates to the remainder obtained after dividing
a by b. For example:
7 % 2 1
12 % 3 0
Increment or Decrement operators
In C, specialized operators have been set aside for the incrementing and decrementing of integer variables. The increment and decrement operators are ++ and -- respectively.
These operators allow a form of shorthand in C:
++i; is equivalent to i=i+1;
--i; is equivalent to i=i-1;
The above example shows the prefix form of the increment/decrement operators. They can also be used in postfix form, as follows:
i++; is equivalent to i=i+1;
i--; is equivalent to i=i-1;
No comments:
Post a Comment