Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Operators and Expression
1.
2. An operator is a symbol that
tells the compiler to perform
specific mathematical or
logical manipulations.
3. C++ is rich in built-in
operators and provides following
type of operators:
•Unary Operator
•Arithmetic Operators
•Relational Operators
•Logical Operators
•Bitwise Operators
•Assignment Operators
•Misc Operators
4. Unary Operator Requires single operand
item to perform operation
Assume variable A holds 10 then:
Operator Description Example
A++ or ++A will give
++ Adds two operands
11
Subtracts second operand
-- A-- or --A will give 9
from the first
5. There are following arithmetic operators
supported by C++ language:
Assume variable A holds 10 and variable B holds
20 then:
Operator Description Example
+ Adds two operands A + B will give 30
Subtracts second operand from the
- A - B will give -10
first
* Multiply both operands A * B will give 200
/ Divide numerator by de-numerator B / A will give 2
Modulus Operator and remainder
% B % A will give 0
of after an integer division
6. There are following relational operators
supported by C++ language.
Assume variable A holds 10 and variable B holds
20 then:
7. Opera
Description Example
tor
Checks if the value of two operands is equal or not, if yes then (A == B) is
==
condition becomes true. not true.
Checks if the value of two operands is equal or not, if values are not (A != B) is
!=
equal then condition becomes true. true.
Checks if the value of left operand is greater than the value of right (A > B) is
>
operand, if yes then condition becomes true. not true.
Checks if the value of left operand is less than the value of right (A < B) is
<
operand, if yes then condition becomes true. true.
Checks if the value of left operand is greater than or equal to the (A >= B) is
>=
value of right operand, if yes then condition becomes true. not true.
Checks if the value of left operand is less than or equal to the value (A <= B) is
<=
of right operand, if yes then condition becomes true. true.
8. There are following logical operators supported
by C++ language.
Assume variable A holds 1 and variable B holds 0
then:
Operator Description Example
Called Logical AND operator. If both the operands are non
&& (A && B) is false.
zero then condition becomes true.
Called Logical OR Operator. If any of the two operands is
|| (A || B) is true.
non zero then condition becomes true.
Called Logical NOT Operator. Use to reverses the logical
! state of its operand. If a condition is true then Logical NOT !(A && B) is true.
operator will make false.
9. The Bitwise operators supported by C++ language
are listed in the following table.
Assume variable A holds 60 and variable B
holds 13 then:
Operator Description Example
Binary AND Operator copies a bit to the result if it exists in both (A & B) will give 12 which is
&
operands. 0000 1100
(A | B) will give 61 which is
| Binary OR Operator copies a bit if it exists in either operand.
0011 1101
Binary XOR Operator copies the bit if it is set in one operand but not (A ^ B) will give 49 which is
^
both. 0011 0001
Binary Ones Complement Operator is unary and has the effect of (~A ) will give -60 which is
~
'flipping' bits. 1100 0011
Binary Left Shift Operator. The left operands value is moved left by the A << 2 will give 240 which is
<<
number of bits specified by the right operand. 1111 0000
Binary Right Shift Operator. The left operands value is moved right by the A >> 2 will give 15 which is
>>
number of bits specified by the right operand. 0000 1111
10. There are following assignment operators
supported by C++ language:
11. Oper
Description Example
ator
Simple assignment operator, Assigns values from right side operands to left side C = A + B will assign
=
operand value of A + B into C
Add AND assignment operator, It adds right operand to the left operand and assign the C += A is equivalent to
+=
result to left operand C=C+A
Subtract AND assignment operator, It subtracts right operand from the left operand C -= A is equivalent to
-=
and assign the result to left operand C=C-A
Multiply AND assignment operator, It multiplies right operand with the left operand C *= A is equivalent to
*=
and assign the result to left operand C=C*A
Divide AND assignment operator, It divides left operand with the right operand and C /= A is equivalent to
/=
assign the result to left operand C=C/A
Modulus AND assignment operator, It takes modulus using two operands and assign C %= A is equivalent
%=
the result to left operand to C = C % A
C <<= 2 is same as C =
<<= Left shift AND assignment operator
C << 2
C >>= 2 is same as C =
>>= Right shift AND assignment operator
C >> 2
C &= 2 is same as C =
&= Bitwise AND assignment operator
C&2
C ^= 2 is same as C =
^= bitwise exclusive OR and assignment operator
C^2
C |= 2 is same as C = C
|= bitwise inclusive OR and assignment operator
|2
12. There are few other operators supported by C++ Language.
Operator Description
Size of operator returns the size of a variable. For example size of(a), where a is
Size of
integer, will return 4.
Conditional operator. If Condition is true ? then it returns value X : otherwise
Condition ? X : Y
value Y
Comma operator causes a sequence of operations to be performed. The value of
, the entire comma expression is the value of the last expression of the comma-
separated list.
. (dot) and -> Member operators are used to reference individual members of classes,
(arrow) structures, and unions.
Casting operators convert one data type to another. For example, int(2.2000)
Cast
would return 2.
Pointer operator & returns the address of an variable. For example &a; will give
&
actual address of the variable.
Pointer operator * is pointer to a variable. For example *var; will pointer to a
*
variable var.
13.
14. *Expression in C++ is form when we combine
operands (variables and constant) and C++
Operators.“
*Expression can also be defined as:
"Expression in C++ is a combination of
Operands and Operators.“
*Operands in C++ Program are those values
on which we want to perform perform
operation.
15.
16. "An expression in which arithmetic
operators are used is called
arithmetic expression“.
For example an arithmetic expression
is look just like that a+b=5
17. "A relational operator with constants and
variables makes relational expression or An
expressions in which relational operators are use
is called relational expression.
Points about relational operators :-
1.Relational operators are use to compare values.
2.All the expressions evaluates from left to
right.
3.There are six relational operators in C++
programming (>,<,>=,<=,==,!=).
4.These operators evaluates results true or
false.
5.False statement represent by 0 and True
statement represent by 1.
6.These operators evaluate at statement level and
has no preference.
18. 1. There are three logical operators And( && ),or( || ) these two
both are binary operator and not( ! ) is u nary operator.
2. More than one relation expression are combine by using logical
operators.
3. The expression will evaluate from left to right if more than one
relation expression are use.
19. Example 1 . write the corresponding C++
expression for the following mathematical
expression ?
1.2 – ye2y + 4y
2.P + q /(r + s)4
Solution = 1. 2-y*exp(2*y)+4*y
= 2. p+q/ pow ((r+s),4)