Arithmetic Operators
Arithmetic Operators are those which we use in order to perform mathematical operations.
Following table shows all the arithmetic operators supported by C language.
Operators | What They Do .. | Precedence |
---|---|---|
++ | Performs Increment (by 1) on Operand | 1 |
-- | Performs Decrement (by 1) on Operand | 1 |
* | Performs Multiplication on Operands | 2 |
/ | Performs Division on Operands | 2 |
% | Performs Modulus operation on Operands , gives remainder after complete division | 2 |
+ | Performs Addition on Operands | 3 |
- | Performs Subtraction on Operands | 3 |
Increment (++)
The Increment-Decrement Operators work by adding/subtracting 1 from the number.
They are of 2 types :
Syntax:
++[variable] or [variable]++
Example:
int main() { int a=10; printf("a=%d",a); //Value in memory and printed : a=10 a++; // Value in memory : a=11; printf("\na=%d",a); printf("\na=%d",a++); // Value 1st Printed ( a=11 ) then changed in memory... printf("\na=%d",a); // Value of a = 12 return 0; }
Decrement (--)
The Decrement Operators work by subtracting 1 from the number.They are of 2 types :
Syntax:
--[variable] or [variable]--
Example:
#include<stdio.h> int main() { int a=10; printf("a=%d",a); //Value in memory and printed : a=10 a--; // Value in memory : a=9; printf("\na=%d",a); printf("\na=%d",a--); // Value 1st Printed ( a=9 ) then changed in memory... printf("\na=%d",a); // Value of a = 8 return 0; }