Arithmetic Operators in c
Arithmetic Operators in c
For instance, "x" is an arithmetic operator that indicates multiplication, while "&&" is a logical
operator representing the logical AND function in programming
Page 1 of 6
Assignment Operators in C
Assignment operators are used to assign value to a variable. The left side
operand of the assignment operator is a variable and the right side operand
of the assignment operator is a value. The value on the right side must be of
the same data type as the variable on the left side otherwise the compiler will
raise an error.
Symbol Operator Description Syntax
Assign the value of
Simple
= the right operand to a=b
Assignment
the left operand.
Page 2 of 6
Arithmetic Operators:
C++ offers various arithmetic operators to perform mathematical calculations on numeric data
types (Integer, Double). Here's a breakdown of the common operators:
Addition (+): Adds two operands (e.g., a + b).
Subtraction (-): Subtracts the second operand from the first (e.g., a - b).
Multiplication (*): Multiplies two operands (e.g., a * b).
Division (/): Divides the first operand by the second (e.g., a / b). Be cautious of division
by zero errors.
Integer Division (\): Performs integer division, discarding any remainder (e.g., 10 \ 3
results in 3).
Modulus (%): Returns the remainder after division (e.g., 10 % 3 results in 1).
Symbol Operation Explanation
This operation adds both the operands on either
+ Addition (a+b)
side of the + operator.
This operation subtracts the right-hand operand
- Subtraction (a-b)
from the left.
* Multiplication (a*b) This operation multiplies both the operands.
This operation divides the left-hand operand by
/ Division (a/b)
the operand on the right.
This operation returns the remainder after
% Modulus (a%b) dividing the left-hand operand by the right
operand.
+ Unary Plus Used to specify the positive values.
+a
– Unary Minus Flips the sign of the value.
-a
++ Increment Increases the value of the operand by 1.
a++
-- Decrement Decreases the value of the operand by 1.
a--
Page 3 of 6
Expressions:
Expressions combine variables, constants, operators, and function calls to evaluate a result. Here
are some points to remember:
Order of Operations (PEMDAS): PEMDAS (Parentheses, Exponents, Multiplication and
Division from left to right, Addition and Subtraction from left to right) dictates the order
of evaluation in expressions.
Data Type Compatibility: The data type of the result depends on the data types of the
operands and the operators used. Mixing data types might require explicit data
conversion.
Page 4 of 6
Relational operators and logical operators
In C++,
“Relational operators and logical operators are fundamental tools for making decisions and
controlling program flow based on conditions.”
Here's a breakdown of these concepts:
1. Relational Operators:
Relational operators compare two values and return a Boolean result (True or False).
They are used in expressions to evaluate relationships between values.
Common Relational Operators:
Operator Description Example
Checks if the left operand is less than the age < 18 evaluates to True if age is less
<
right than 18
Checks if the left operand is greater than the score > 90 evaluates to True if score is
>
right greater than 90
Checks if the left operand is less than or balance <= 0 evaluates to True if
<=
equal to the right balance is 0 or less
Checks if the left operand is greater than or grade >= B evaluates to True if grade is
>=
equal to the right B or higher
Page 5 of 6
2- Common Logical Operators:
Returns True only if both x > 0 And y < 10 evaluates to True if x is positive
And
conditions are True AND y is less than 10
Returns True if at least one age >= 65 Or is Student evaluates to True if age is 65
Or
condition is True or older OR is Student is True
Page 6 of 6