Well , we all learned the basic math in lower grades. There is nothing new to the arithmetic operators in C . All is the same.
+ addition or unary plus
- subtraction or unary minus
% remainder after division (modulo division)
We have another set of operators called Increment and Decrement operators , this will be helpful in "loops " . We will get to the loops later.
Let a=5 and b=10
a++; //a becomes 6-post increment
a--; //a becomes 5-post decrement
++a; //a becomes 6-pre increment
--a; //a becomes 5-pre decrement.
POST - this means first the value 5 is assigned to a variable and the operation wrt to the sign is done.
PRE - this means that the value is first incremented/decremented depending on the sign and then assigned to the variable.
To write conditions ,we need relational and logical operators.
== Equal to 5==3 returns false (0)
> Greater than 5>3 returns true (1)
< Less than 5<3 returns false (0)
!= Not equal to 5!=3 returns true(1)
>= Greater than or equal to 5>=3 returns true (1)
<= Less than or equal to 5<=3 return false (0)
&& Logial AND If c=5 and d=2 then,((c==5) && (d>5)) returns false.
|| Logical OR If c=5 and d=2 then, ((c==5) || (d>5)) returns true.
! Logical NOT If c=5 then, !(c==5) returns false.
We also have another category of operator called Ternary operator ( Conditional Operator )
The syntax is:
If the Conditional_expression is true then Expression1 is executed.
If the conditional_expression is false then Expression2 is executed.
Please have a look at the file attached to understand how operators work.