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

Computer Science: Operators

This document summarizes common operators in C++. It describes arithmetic operators like unary, binary, and ternary operators. It also covers increment/decrement, relational, logical, conditional, sizeof, and comma operators. The core functions of each operator type are defined through examples, such as unary operators acting on a single operand and binary operators working with two operands. Relational operators determine relations between operands and return true or false. Logical operators combine expressions and conditional operators store values depending on conditions.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Computer Science: Operators

This document summarizes common operators in C++. It describes arithmetic operators like unary, binary, and ternary operators. It also covers increment/decrement, relational, logical, conditional, sizeof, and comma operators. The core functions of each operator type are defined through examples, such as unary operators acting on a single operand and binary operators working with two operands. Relational operators determine relations between operands and return true or false. Logical operators combine expressions and conditional operators store values depending on conditions.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

COMPUTER SCIENCE

OPERATORS
INTRODUCTION
The operations are represented by operators and object
of operations are known as operands .

C++ consists of set of operators.

1. Arithmetic Operator

2. Relational Operator

3. Conditional Operator

4. Increment/Decrement Operator

5. Logical Operator
ARITHMETIC OPERATOR
There are three types of arithmetic operator:- Unary operator, Binary operator,
Ternary operator.

UNARY OPERATOR:
The operator that act on single operand are known as Unary Operator
1. Unary + :-This operator precedes an operand. The operand of unary + operator
must have arithmetic or pointer type and results is the value of the argument.
Example: a=5 then +a means 5
a= -5 then +a means -5

2. Unary - :- This operator


precedes an operand. The operand of the unary -
operator must have arithmetic type and the result is the negation of its
operand’s value.
Example: a=5 then -a means -5
a= -5 then -a means +5
BINARY OPERATORS

Operators that works on two operators are referred to as


Binary Operators.

Types:
1. Addition operator +

2. Subtraction operator -

3. Multiplication operator *

4. Division operator /

5. Modulus Opearator %
INCREMENT/DECREMENT OPERATORS

C++ includes two operators increment and decrement

There are two versions of these operators : prefix and postfix

 Prefix :- ++a
 Postfix :- a++
WORKING WITH PREFIX VERSION

In this version, the operator comes before the operand . C


++ performs increment or decrement before using the value
of the operand . It follows change then use rule i.e first
change the value of the new value in evaluating the
exression.
WORKING WITH POSTFIX VERSION

In this version, the increment or decrement follows its


operands. C ++ uses the value of the operand in evaluating
the expression before incrementing or decrementing the
operands value. Thus it follows use then change
RELATIONAL OPERATORS
They determine the relation among different operands. The result of
relational expression is true(1) / false(0). C++ provides 6 relational
operators for comparing numbers and character.
1. < (less than)
2. > (greater than)
3. <= (less than or equal to)
4. >= (greater than or equal to)

5. == (equal to)
6. != (not equal to)
LOGICAL OPERATORS
C++ provides three logical operators to combine existing
expressions.

1. LOGICAL ‘OR’ OPERATOR (ll)

It combines two expressions and evaluates to true if either


of its operands evaluate to true.
Example:- (4==8)ll(5==5

=> 0 ll 1
=> 1
2. LOGICAL ‘AND’ OPERATOR (&&)

Logical ‘AND’ operator combines two operations and


resulting expression has true value only when both the
expression are true.
Example:- (6==6)&& (5==7)
=> 1 && 0

=> 0
3. LOGICAL ‘NOT’ OPERATOR (!)

Logical ‘NOT’ operator works on single expression or


operation. This operator negates or reverse the truth value of
the expression
Example:- ! (5>2)
=> 0
4. CONDITIONAL OPERATOR ( ? ! )

C++ offers conditional operator that stores a value


depending on a condition. This operator is known as ternary
operator as it requires three operands.

General form for declaring conditional operator :-


expression1 ? expression2 ?expression3
COMPILE TIME OPERATOR

Its a unary operator that returns the length of the


variable that it precedes general form of size of operator is

sizeof var (where var is a declared variable)


sizeof (type) (where type is a C++ data type).
THE COMMA OPERATOR

A comma operator is used to string together several


expressions.
The comma operator has lowest precedence to all these
operators.
THANK YOU

By

SHIVANI BORTHAKUR
Class – XIth
Sec - B

You might also like