Arithmetic Operators

Here are the common arithmetic operators:

+

Used to add numbers. It can also be used to perform string concatenation.

-

Used to perform subtraction. It can also be used to perform string subtraction. For example, 'cat, dog, mouse' - ', dog' results in the string 'cat, mouse‘.

*

Used to multiply numbers.

/

Used to divide numbers. Note that NASL will return a 0 if you try to divide by zero.

%

Used to perform a modulo operation. For example, 10%3 computes to 1.

**

Used to perform exponentiation. For example, 2**3 computes to 8.

++

Used to increment a variable’s value by 1. When a variable is prefixed by this operator (example: ++c), its value is incremented before it is evaluated. When a variable is post-fixed by this operator (example: c++), its value is incremented after it is evaluated.

Used to decrement a variable’s value by 1. When a variable is prefixed by this operator (example: --c), its value is decremented before it is evaluated. When a variable is post-fixed by this operator (example: c--), its value is decremented after it is evaluated.

Get Network Security Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.