Relations and logical operators

Relations

Equals

int x = 1;
int y = 1;

int z = x == y;

Not equals

int x = 1;
int y = 1;

int z = x != y;

Greater than and less than

int x = 1;
int y = 1;

int z = x > y;
int x = 1;
int y = 1;

int z = x < y;

Greater or equal than and less or equal than

int x = 1;
int y = 1;

int z = x >= y;
int x = 1;
int y = 1;

int z = x <= y;

Logic

Logical AND, and short-circuiting for AND

Returns \(1\) if both positive. \(0\) otherwise.

If first is not truthy, the second is not evaluated.

int x = 1;
int y = 0;

int z = x && y;

Logical OR, and short-circuiting for OR

Returns \(1\) if either positive. \(0\) otherwise.

If first is truthy, the second is not evaluated.

int x = 1;
int y = 0;

int z = x || y;

Logical NOT

int x = 1;
int y = 0;

int z = !(x && y);