Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Operator: Show Examples

Operators are symbols that tell the compiler to perform mathematical or logical manipulations. There are two main types of operators in C++: arithmetic operators, which are used for mathematical calculations like addition and multiplication, and relational operators, which are used for comparisons like equality and greater than. Arithmetic operators include addition, subtraction, multiplication, division, and modulus. Relational operators include equality, inequality, greater than, less than, greater than or equal to, and less than or equal to. Operator precedence determines the order that terms are evaluated in an expression.

Uploaded by

Ali Ammar Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Operator: Show Examples

Operators are symbols that tell the compiler to perform mathematical or logical manipulations. There are two main types of operators in C++: arithmetic operators, which are used for mathematical calculations like addition and multiplication, and relational operators, which are used for comparisons like equality and greater than. Arithmetic operators include addition, subtraction, multiplication, division, and modulus. Relational operators include equality, inequality, greater than, less than, greater than or equal to, and less than or equal to. Operator precedence determines the order that terms are evaluated in an expression.

Uploaded by

Ali Ammar Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Operator

An operator is a symbol that tells the compiler to perform specific mathematical or


logical manipulations. C++ is rich in built-in operators and provide various types of
operators, two of them are:

 Arithmetic Operators
 Relational Operators

Arithmetic Operators
There are following arithmetic operators supported by C++ language −
Assume A holds 10 and B holds 20, then −
Show Examples

Operato Description Example


r

+ Adds two operands A + B will give 30

- Subtracts second operand from the first A - B will give -10

* Multiplies both operands A * B will give 200

/ Divides numerator by de-numerator B / A will give 2

% Modulus Operator and remainder of after an B % A will give 0


integer division

++ Increment operator, increases integer value A++ will give 11


by one

-- Decrement operator, decreases integer A-- will give 9


value by one

Relational Operators
There are following relational operators supported by C++ language
Assume A holds 10 and B holds 20, then −
Show Examples
Operato Description Example
r

== Checks if the values of two operands are (A == B) is not true.


equal or not, if yes then condition becomes
true.

!= Checks if the values of two operands are (A != B) is true.


equal or not, if values are not equal then
condition becomes true.

> Checks if the value of left operand is greater (A > B) is not true.
than the value of right operand, if yes then
condition becomes true.

< Checks if the value of left operand is less (A < B) is true.


than the value of right operand, if yes then
condition becomes true.

>= Checks if the value of left operand is greater (A >= B) is not true.
than or equal to the value of right operand, if
yes then condition becomes true.

<= Checks if the value of left operand is less (A <= B) is true.


than or equal to the value of right operand, if
yes then condition becomes true.

Operators Precedence in C++


Operator precedence determines the grouping of terms in an expression. This affects
how an expression is evaluated. Certain operators have higher precedence than
others; for example, the multiplication operator has higher precedence than the
addition operator −
For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence will be evaluated first.

You might also like