Types, Operators and Expressions Hint: Use arithmetic operators + and Operators ++ , Prefix increment c = 5; x = ++c; /* value of c is 6 and x is 6 */
PROG0101 Fundamentals of Programming 2 Operators Topics • Operators • Arithmetic Operators • Relational Operators • Logical Operators • Increment and
C language is rich in built-in operators and provides the following types of operators: Arithmetic Operators Relational Operators Logical Operators
Any combination of variables, constants, operators, and function calls every expression has a type, derived from the types of its components (according to C
Here, the symbol = is an example of one type of operator, called an assignment operator You learn more about operators later in this chapter The name of a
Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte Bitwise operator works on bits and performs
called operator Python language supports the following types of operators Arithmetic Operators Comparison (i e , Relational) Operators Assignment Operators
Downloaded from startertutorials com (or) stuts me 1 Types, Operators, and Expressions Types In general, the structure of a Python program is as follows:
Learn Python's arithmetic, string, relational, logical, bit–wise operators • Learn Python's sequence operators (with examples from the string type) • Learn about
2 fév 2000 · this section list SQL operators Unary and Binary Operators There are two general classes of operators: unary A unary operator operates on
[PDF] types of oral presentation
[PDF] types of organizational structure
[PDF] types of phrases in english
[PDF] types of phrases in english grammar examples
[PDF] types of phrases in english grammar exercises
[PDF] types of phrases in english grammar pdf
[PDF] types of phrases in english grammar ppt
[PDF] types of phrases in english pdf
[PDF] types of phrases in english syntax
[PDF] types of phrases ppt
[PDF] types of priority scheduling
[PDF] types of probability pdf
[PDF] types of programming language
[PDF] types of programming languages
[PDF] types of queries in information retrieval
PROG0101 Fundamentals of Programming
1
PROG0101
FUNDAMENTALS OF PROGRAMMING
Chapter 5
Operators
PROG0101 Fundamentals of Programming
2
Operators
Topics
Operators
Arithmetic Operators
Relational Operators
Logical Operators
Increment and Decrement Operators
PROG0101 Fundamentals of Programming
3
Operators
Operators
Anoperatorisasymbol,whichhelpstheuserto
orlogicalmanipulations.
Operatorsareusedinprogramminglanguage
programtooperateondataandvariables.
PROG0101 Fundamentals of Programming
4
Operators
Operators
Operatorscanbeclassifiedas:
Arithmeticoperators
RelationalOperators
LogicalOperators
IncrementsandDecrementOperators
PROG0101 Fundamentals of Programming
5
Operators
Arithmetic Operators
numericvalues.
OperatorNameDescription
+Additionto add two numbers together -Subtractionto subtract one number from another *Multiplicationto multiply one number by another. /Divisionto divide one number by another. %Modulus (Remainder) to find the remainder from dividing one number by another.
PROG0101 Fundamentals of Programming
6
Operators
Arithmetic Operators
Example:
i.5+3=8 ii.53=2 iii.5*3=15 iv.5/3=1 v.5%3=2
PROG0101 Fundamentals of Programming
7
Operators
Arithmetic Operators
*,/and%willbeperformedbefore+or-inany expression. evaluationtothis.
PROG0101 Fundamentals of Programming
8
Operators
Arithmetic Operators
Example
i.2 + 5 * 4 3 = ? ii.(2 + 5) * (4 3) = ?
PROG0101 Fundamentals of Programming
9
Operators
Arithmetic Operators
assignmentstatements: i.z = x + y ii.no1 = x y iii.age = a * b + c iv.velocity = distance / time v.force = mass * acceleration vi.count = count + 1
PROG0101 Fundamentals of Programming
10
Operators
Integer Arithmetic
calledasintegerarithmetic.
Italwaysgivesanintegerastheresult.
PROG0101 Fundamentals of Programming
11
Operators
Integer Arithmetic
Example
Letx=27andy=5betwointegernumbers.Thenthe
i.x + y = 32 ii.x y = 22 iii.x * y = 115 iv.x % y = 2 v.x / y = 5
PROG0101 Fundamentals of Programming
12
Operators
Floating-point Arithmetic
iscalledfloating-pointarithmetic.
PROG0101 Fundamentals of Programming
13
Operators
Floating-point Arithmetic
Example
Let x = 14.0 and y = 4.0 then
i.x + y = 18.0 ii.x y = 10.0 iii.x * y = 56.0 iv.x / y = 3.50
PROG0101 Fundamentals of Programming
14
Operators
Relational Operators
Anoperatorthatcomparestwovalues.
Forexample,theexpression:
ThisexpressionwillhaveavalueofTRUEifthe
expressionwillbeFALSE. x < 5 means x is less than 5
PROG0101 Fundamentals of Programming
15
Operators
Relational Operators
Relationaloperatorsaresometimescalled
comparisonoperators. calledrelationalexpressions.
Whereexp1andexp2areexpressions,whichmay
them.
relational operator PROG0101 Fundamentals of Programming
16 Operators
Relational Operators
Thefollowingarerelationaloperators:
OperatorNameDescription
Indicates whether the value of the left operand is less than the value of the right operand. <=Less than or equal to Indicates whether the value of the left
operand is less than or equal to the value of the right operand. >Greater than Indicates whether the value of the left
operand is greater than the value of the right operand. >=Greater than or equal to Indicates whether the value of the left
operand is greater than or equal to the value of the right operand. PROG0101 Fundamentals of Programming
17 Operators
Relational Operators
Thefollowingarerelationaloperators:
OperatorNameDescription
==Equal to Indicates whether the value of the left
operand is equal to the value of the right operand. !=Not equal to Indicates whether the value of the left
operand is not equal to the value of the right operand. PROG0101 Fundamentals of Programming
18 Operators
Relational Operators
Example:
Letx=2andy=5then
i.x < y = True ii.(x + 2) > (y * 2)= False iii.(x + 3) <= y = True iv.x != y = True v.y > (3 + x)= False PROG0101 Fundamentals of Programming
19 Operators
Logical Operators
relationalexpressions. Thefollowingarelogicaloperators:
OperatorName
&&LogicalAND ||LogicalOR !Logical NOT PROG0101 Fundamentals of Programming
20 Operators
Logical AND
expressionistrue. Exp1Exp2Exp1 && Exp2
FalseFalseFalse
TrueFalseFalse
FalseTrueFalse
TrueTrueTrue
PROG0101 Fundamentals of Programming
21
Operators
Logical AND
Example:
(a > b) && (x == 10) equalto10. PROG0101 Fundamentals of Programming
22
Operators
Logical AND
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: i.(a > b) && (c != 5)= False ii.(a < b) && (c < b)= False iii.(a > b) && (c == 5) = False iv.(a < b) && (b < c)= True PROG0101 Fundamentals of Programming
23
Operators
Logical OR
istrue. orifbothofthemaretrue. Exp1Exp2Exp1 || Exp2
FalseFalseFalse
TrueFalseTrue
FalseTrueTrue
TrueTrueTrue
PROG0101 Fundamentals of Programming
24
Operators
Logical OR
Example:
(a < m) || (a < n) trueorifbothofthemaretrue. PROG0101 Fundamentals of Programming
25
Operators
Logical OR
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: i.(a > b) || (c != 5)= False ii.(a < b) || (c < b)= True iii.(a > b) || (c == 5) = True iv.(a < b) || (b < c)= True PROG0101 Fundamentals of Programming
26
Operators
Logical NOT
evaluatestofalseiftheexpressionistrue. Inotherwordsitjustreversesthevalueofthe
expression. Exp1!Exp1
TrueFalse
FalseTrue
PROG0101 Fundamentals of Programming
27
Operators
Logical NOT
Example:
! (x >= y) ofxisneithergreaterthanorequaltoy PROG0101 Fundamentals of Programming
28
Operators
Logical NOT
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: a) !(a > b)= True b) !(a < b) = False c) !(a > b || c == 5)= False PROG0101 Fundamentals of Programming
29
Operators
Increment and Decrement Operators
theunaryoperatorswhichareveryusefulin programminglanguage. Theyareextensivelyusedinloops.
Thesyntaxoftheoperatorsisgivenbelow:
++ variable name variable name++ quotesdbs_dbs21.pdfusesText_27