Unary Operators

Logical Operators

NOT (!, not)

% C-style
result: int = !x

% Python style
result: int = not x

Bitwise Operators

Bitwise NOT (~)

% 1010 becomes 0101
result: int = ~x

Memory Operations

Dereference (.*)

ptr: *int = value.&

% Get value at ptr
result: int = ptr.*

Address-of (&)

value: int = 42

% Get address of value
ptr: *int = value.&

Increment/Decrement

Pre-increment (++x)

% Increment before use
++x

% Equivalent operation
x += 1

Pre-decrement (--x)

% Decrement before use
--x

% Equivalent operation
x -= 1

Post-increment (x++)

% Use before increment
x++

Post-decrement (x--)

% Use before decrement
x--

Example Differences

Pre vs Post Increment

x = 42

% Pre-increment: Increment x before its value is used
result = ++x  % result is 43, x is now 43

% Post-increment: Increment x after its value is used
result = x++  % result is 43, x is now 44
x = 42

% Pre-decrement: Decrement x before its value is used
result = --x  % result is 41, x is now 41

% Post-decrement: Decrement x after its value is used
result = x--  % result is 41, x is now 40

Last updated