-->





C++ OPERATOR AND EXPRESSION IN C++

EXPRESSION IN C++
"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.
There are three types of expressions:

  1. Arithmetic expression
  2. Relational expression
  3. Logical expression

What is a C++ OPERATOR?
"C++ OPERATORS are signs use to perform certain task e.g addition"
There are two kinds of operators:
a) Unary operator b) Binary operator
What is the difference between Unary and Binary operator?
Unary operators:
"Requires single operand item to perform operation".
Binary operators:
"Required more than one operand item to perform operation".
Types of operators :

  1. Arithmetic operators
  2. Relational operators
  3. Logical operators
  4. Increment and decrement operators
  5. Assignment operator
  6. Bit-wise operator

Arithmetic Expression and Arithmetic operator
"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
Explanation:
LIST OF ARITHMETIC OPERATORS AND THEIR FUNCTIONS
C++ basic operators and their functions
C++ basic operators and their functions
  • These are used for all kind of numeric data.
  • "%" is also called modulus operator it can be use only with integers.
  • Unary operators has higher precedence as compared to binary operators.
  • 3.Multiplication(*) and Division(/) as higher priority than addition(+) and subtraction(-) where addition and division has equal priority.

Modes of Arithmetic Expressions

  1. 1.Mixed arithmetic
  2. 2.Real arithmetic
  3. 3.Integer arithmetic

Integer arithmetic mode
In this mode when arithmetic operation perform by using integer values it always result an integer value.
for example:
a=5 , b=5

a*b=25 , a/b=1 , a+b=10 , a-b=0
Real arithmetic mode
In this mode when a arithmetic operation is performed by using

floating point numbers it always result an floating value.
a=10.0 , b=5.0

a*b=50.0 a/b=2.0 a+b=15.0 a-b=5.0
Mixed arithmetic mode
In this mode when an arithmetic operation performed on float and integer values it always result a float value.
For example:
a=10 , b=5.0
a*b=50.0,a/b=2.0,a+b=15.0,a-b=5.0
Relational operators and relational expressions
"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.

Logical Expression and Logical Operators
Logical operators

  • 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.

And operator (&&)

  • It produces true result if all the expression or conditions are true.
  • It produces false if any one expression is false.
  • Below table shows evaluation method of and operator.
  • 1 represent True 0 represent false.

Example to understanding of And ( && ) operator.
a=10,b=5
Or operator( || )

  • 1.It produces true if any expression is true.
  • 2.It produces false if all the conditions are false.
  • Below table shows evaluation method of Or( || ) operator.



Example to understanding of And ( || ) operator.
a=10,b=5,
Not operator( ! )

  • 1.If expression provides true result it convert it into false.
  • 2.If expression provides false result it convert it into true.

Evaluation method.
Result ! Result
1 0
0 1
Example to understanding of And ( ! ) operator.
a=10,b=5

2 comments: