0% found this document useful (0 votes)
2 views

Operator

The document provides an overview of various operators in programming, including arithmetic, relational, logical, increment/decrement, and assignment operators. Each operator is illustrated with examples demonstrating their usage in code. This serves as a reference for understanding how to perform operations and comparisons in programming.

Uploaded by

klee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Operator

The document provides an overview of various operators in programming, including arithmetic, relational, logical, increment/decrement, and assignment operators. Each operator is illustrated with examples demonstrating their usage in code. This serves as a reference for understanding how to perform operations and comparisons in programming.

Uploaded by

klee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Operators and Expressions

NEL C. HERNANDO, ME, MBA


Arithmetic Operators
+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
% (Modulo - Remainder after division)

int a = 10;
int b = 3;
int sum = a + b; // sum = 13
int difference = a - b; // difference = 7
int product = a * b; // product = 30
int quotient = a / b; // quotient = 3
int remainder = a % b; // remainder = 1
Relational Operators
== (Equal to)
!= (Not equal to)
> (Greater than)
< (Less than)
>= (Greater than or equal to)
<= (Less than or equal to)

int x = 5;
int y = 7;
bool isEqual = x == y; // isEqual = false
bool notEqual = x != y; // notEqual = true
bool greaterThan = x > y; // greaterThan = false
bool lessThan = x < y; // lessThan = true
bool greaterOrEqual = x >= y; // greaterOrEqual = false
bool lessOrEqual = x <= y; // lessOrEqual = true
Logical Operators

&& (Logical AND)


|| (Logical OR)
! (Logical NOT)

bool p = true;
bool q = false;
bool logicalAnd = p && q; // logicalAnd = false
bool logicalOr = p || q; // logicalOr = true
bool logicalNot = !p; // logicalNot = false
Increment/Decrement Operators

++ (Increment)
-- (Decrement)

int count = 5;
count++; // Increment count by 1 (count = 6)
count--; // Decrement count by 1 (count = 5)
Assignment Operators
**=** (Assignment)
+= (Addition assignment)
-= (Subtraction assignment)
*= (Multiplication assignment)
/= (Division assignment)
%= (Modulo assignment)

int num = 10;


num += 5; // Equivalent to num = num + 5 (num = 15)
num -= 3; // Equivalent to num = num - 3 (num = 12)
num *= 2; // Equivalent to num = num * 2 (num = 24)
num /= 4; // Equivalent to num = num / 4 (num = 6)
num %= 5; // Equivalent to num = num % 5 (num = 1)

You might also like