Operators
Assignment operator
=
This operator assigns a value to a variable. For example:
c = 12;
Arithmetic operators:
+ addition
- subtraction
* multiplication
/ division
% modulo
For examples:
a = 2 + 3;
b = 9 - 2;
c = 4 * 5;
d = 6 / 4;
e = 2 % 3;
Relational and equality operators:
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Let's see some examples:
a == b // a equal to b
5 > 4 // 6 is greater than 3
b != c // b no equal to c
e >= f // e equal to or grater than f
3 < 5 // 3 is less than 5 Logical operators:
! No
&& And
|| Or
For examples:
!(a==b) //not "a equal to b"
(a==b) && (b==c)//"a equal to b" AND "b equal to c"
(a==b) || (c==b)//"a equal to b" OR "c equal to b" Conditional
operator
?
The syntax of using Conditional operator is:
condition ? result1 : result2
If condition is true, it will return result1, if it is not, it will return
result2. For example:
9>7 ? a : b
It will return "a" because the condition "9>7"
is true.
|