Operators

An expression is a sequence of operators and their operands, that specifies a computation.

Binary Operators

Operators
Explanation

+

Add two values

-

Subtract one value from another

*

Multiply two values

//

Divide two values

%

Modulo of a value

<

Check if one value is less than another

<=

Check if one value is less than or equal to another

>

Check if one value is greater than another

>=

Check if one value is greater than or equal to another

!=

Check if one value is different from another

==

Check if two values are equal

Here is an example of each binary operators:

+

(a = (1 + 2))

Here a = 3.

-

Here a = 1.

*

Here a = 4.

//

Here a = 5.

%

Here a = 5.

<

Here a = 10.

<=

Here a = 10.

>

Here a = 10.

>=

Here a = 10.

!=

Here a = 10.

==

Here a = 10.

Operators Priority

The C-- defines different priority for each operators, it is defined by a number that go from 1 (very low priority) to 9 (biggest priority)

Here is a table with the default priority for operators:

Priority
Operators

4

[ +, -]

5

[ *, //, % ]

6

[==, !=, >, >=, <, <=]

Considering the following example, we can see that we can chain operators when we want to compute values:

Here, the integer i will be equal to 3 and b equal to 9 considering the calculation priority.

Infix Operators

In C-- it's possible to change the operator priority and it's possible to assign an operating priority to functions

Example:

In this case tona is considered as an infix operator and the * operator has a lower priority than tona. So here i = 3 tona 7 * 3. So i = 3 * 3 = 9.

Another example:

In this case tona is considered as an infix operator but it acts like the + operator. In C-- `+`= means +=. So here a = 6.

Unary Operators

Operators
Explanation

&

Access the address of a value

?

Dereference a pointer

++

Increment

--

Decrement

Here is an example of each unary operators:

&

Here the character stored in the variable c is written.

?

Here (?h) dereference its pointer.

++

Here the string strg is displayed because the value a is incremented to 2 with the ++ operator.

--

Here the string strg is displayed because the value a is incremented to 2 with the -- operator.

Post-fix Operators

Operators
Explanation

[]

Access an index

[]

Here the 5th character of str is c.

Last updated