SlideShare a Scribd company logo
1 of 21
Operators
&
Expressions
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
1
Operator
• Is a symbol that directs the computer to perform certain operations.
• Operations are performed on operands.
• Operation is an action performed on one or more operands.
• Operations can be mathematical or logical.
• Operands can be a variable, constant, or an expression.
• Are used to manipulate data and variables.
• Usually form a part of mathematical or logical expressions.
• Can be unary, binary or ternary.
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
2
Classification of operators
Arithmetic
Relational
Logical
Assignment
Increment and decrement
Conditional
Bitwise
Special
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
3
Arithmetic Operators
+
•Addition or unary plus
• a+b
-
•Subtraction or unary minus
• a-b
*
•multiplicatiion
• a*b
/
•Division
• a/b
%
•Modulo division
• a%b
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
4
Types of Arithmetic operators
Integer arithmetic
Real arithmetic
Mixed-mode
arithmetic
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
5
Relational operators
<
• is less than
• a<b
<=
• is less than or equal to
• a<=b
>
• is greater than
• a>b
>=
• is greater than or equal to
• a>=b
==
• is equal to
• a==b
!=
• is not equal to
• a!=b
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
6
Logical operators
&& - Logical AND
|| - Logical OR
! - Logical NOT
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
7
Logical operators
Operand 1 Operand 2 Value of the expression
Operand 1 &&
Operand 2
Operand 1 ||
Operand 2
Non-zero Non-zero 1 1
Non-zero 0 0 1
0 Non-zero 0 1
0 0 0 0
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
8
Assignment operators
• Most commonly used binary operator.
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
9
Operator Use Effect
+= a+=b; a=a+b;
-= a-=b; a=a-b;
*= a*=b; a=a*b;
/= a/=b; a=a/b;
%= a%=b; a=a%b;
Increment & decrement operator
++m
m++
++
--m
m--
--
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
10
Rules for ++ and - - operator
Are unary operators and require variables as their operands.
When postfix ++ (or --) used with a variable, expression is evaluated with
the original value of the variable and then incremented or decremented.
When prefix ++v(or --) used, the variable is incremented first and
expression is evaluated using the new value of the variable.
Precedence and associativity is same as unary + or unary -.
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
11
Conditional operator
It is a ternary operator.
exp1?exp2:exp3
exp1, exp2, exp3 are expressions.
x=(a>b)?a:b;
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
12
Bitwise operator
&
• Bitwise AND
|
• Bitwise OR
^
• Bitwise exclusive OR
<<
• Shift left
>>
• Shift right
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
13
Special operators
The comma
operator
The sizeof
operator
• Can be used to link the
related expressions.
• e.g. x=10, y=15
• It is a compile time operator.
• Returns the number of bytes
the operand occupies.
• e.g. m=sizeof(sum);
n=sizeof(long int);
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
14
Expressions
Is a formula
Operands are linked together by the use of operators to
calculate a value.
Operand can be a function, a variable, a constant or an
array.
e.g. a-b; c+d; etc.
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
15
Types of expressions
Expressions
Arithmetic
expressions
Relational
expressions
Logical
expressions
Conditional
expressions
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
16
Precedence & associativity of
operators
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
17
Precedence rules decide the order in which
different operations are applied.
Associativity rules decide in which multiple
occurrences of the same level operator are
applied.
Precedence & associativity
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
18
Operator Description Associativity Rank
( ) Function call Left to Right 1
[ ] Array element reference
+ Unary plus Right to left 2
- Unary minus
++ Increment
-- Decrement
! Logical negation
~ One’s complement
* Pointer reference(indirection)
& Address
sizeof Size of an object
(type) Type cast(conversion)
Precedence & associativity
Operator Description Associativity Rank
* Multiplication Left to Right 3
/ Division
% Modulus
+ Addition Left to right 4
- Subtraction
<< Left shift Left to right 5
>> Right shift
< Less than Left to right 6
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equality Left to right 7
|= Inequality
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
19
Precedence & associativity
Operator Description Associativity Rank
& Bitwise AND Left to right 8
^ Bitwise XOR Left to right 9
| Bitwise OR Left to right 10
&& Logical AND Left to right 11
|| Logical OR Left to right 12
? : Conditional expression Right to left 13
= Assignment operators Right to left 14
*=, /=, %=
+=, -=, &=
^=, |=
<<=, >>=
, Comma operator Left to right 15
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
20
Thank You
By:SatveerKaur,AssistantProfessor,Khalsa
College,Patiala.
21

More Related Content

What's hot

Relational Algebra Operations
Relational Algebra OperationsRelational Algebra Operations
Relational Algebra OperationsShefa Idrees
 
Mathematical and logical operators
Mathematical and logical operatorsMathematical and logical operators
Mathematical and logical operatorsRGn Ebsin
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsortschidabdu
 
Excel IF function
Excel IF functionExcel IF function
Excel IF functionHtay Aung
 
Flowchart design for algorithms
Flowchart design for algorithmsFlowchart design for algorithms
Flowchart design for algorithmsKuppusamy P
 
Machine Learning Interview Question and Answer
Machine Learning Interview Question and AnswerMachine Learning Interview Question and Answer
Machine Learning Interview Question and AnswerLearnbay Datascience
 
Operators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETOperators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETShyam Sir
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...Fernando Loizides
 
Logistic Ordinal Regression
Logistic Ordinal RegressionLogistic Ordinal Regression
Logistic Ordinal RegressionSri Ambati
 
Combinatorial optimization CO-6
Combinatorial optimization CO-6Combinatorial optimization CO-6
Combinatorial optimization CO-6man003
 
WolframAlpha - KS3 part 1
WolframAlpha - KS3 part 1WolframAlpha - KS3 part 1
WolframAlpha - KS3 part 1Colleen Young
 

What's hot (18)

Report on c
Report on cReport on c
Report on c
 
Operators
OperatorsOperators
Operators
 
Relational Algebra Operations
Relational Algebra OperationsRelational Algebra Operations
Relational Algebra Operations
 
Mathematical and logical operators
Mathematical and logical operatorsMathematical and logical operators
Mathematical and logical operators
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsorts
 
Excel IF function
Excel IF functionExcel IF function
Excel IF function
 
Mbd dd
Mbd ddMbd dd
Mbd dd
 
R operators
R   operatorsR   operators
R operators
 
Flowchart design for algorithms
Flowchart design for algorithmsFlowchart design for algorithms
Flowchart design for algorithms
 
Machine Learning Interview Question and Answer
Machine Learning Interview Question and AnswerMachine Learning Interview Question and Answer
Machine Learning Interview Question and Answer
 
Operators
OperatorsOperators
Operators
 
Ch2
Ch2Ch2
Ch2
 
Operators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETOperators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NET
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...
 
CSC410-Presentation
CSC410-PresentationCSC410-Presentation
CSC410-Presentation
 
Logistic Ordinal Regression
Logistic Ordinal RegressionLogistic Ordinal Regression
Logistic Ordinal Regression
 
Combinatorial optimization CO-6
Combinatorial optimization CO-6Combinatorial optimization CO-6
Combinatorial optimization CO-6
 
WolframAlpha - KS3 part 1
WolframAlpha - KS3 part 1WolframAlpha - KS3 part 1
WolframAlpha - KS3 part 1
 

Similar to Operators and expressons

Similar to Operators and expressons (20)

Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Caculus
CaculusCaculus
Caculus
 
Caculus.pptx
Caculus.pptxCaculus.pptx
Caculus.pptx
 
Data Structures Chapter-2
Data Structures Chapter-2Data Structures Chapter-2
Data Structures Chapter-2
 
Operators in C
Operators in COperators in C
Operators in C
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 

More from Satveer Mann

keywords and identifiers
 keywords and identifiers keywords and identifiers
keywords and identifiersSatveer Mann
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesSatveer Mann
 
Program structure of c
Program structure of cProgram structure of c
Program structure of cSatveer Mann
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesSatveer Mann
 
Problem solving process
Problem solving processProblem solving process
Problem solving processSatveer Mann
 
Character set in C
Character set in CCharacter set in C
Character set in CSatveer Mann
 
Introduction to c
 Introduction to c Introduction to c
Introduction to cSatveer Mann
 

More from Satveer Mann (10)

Data types in C
Data types in CData types in C
Data types in C
 
Variables in C
Variables in CVariables in C
Variables in C
 
Constants in C
Constants in CConstants in C
Constants in C
 
keywords and identifiers
 keywords and identifiers keywords and identifiers
keywords and identifiers
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Program structure of c
Program structure of cProgram structure of c
Program structure of c
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodes
 
Problem solving process
Problem solving processProblem solving process
Problem solving process
 
Character set in C
Character set in CCharacter set in C
Character set in C
 
Introduction to c
 Introduction to c Introduction to c
Introduction to c
 

Recently uploaded

Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Operators and expressons

  • 2. Operator • Is a symbol that directs the computer to perform certain operations. • Operations are performed on operands. • Operation is an action performed on one or more operands. • Operations can be mathematical or logical. • Operands can be a variable, constant, or an expression. • Are used to manipulate data and variables. • Usually form a part of mathematical or logical expressions. • Can be unary, binary or ternary. By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 2
  • 3. Classification of operators Arithmetic Relational Logical Assignment Increment and decrement Conditional Bitwise Special By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 3
  • 4. Arithmetic Operators + •Addition or unary plus • a+b - •Subtraction or unary minus • a-b * •multiplicatiion • a*b / •Division • a/b % •Modulo division • a%b By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 4
  • 5. Types of Arithmetic operators Integer arithmetic Real arithmetic Mixed-mode arithmetic By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 5
  • 6. Relational operators < • is less than • a<b <= • is less than or equal to • a<=b > • is greater than • a>b >= • is greater than or equal to • a>=b == • is equal to • a==b != • is not equal to • a!=b By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 6
  • 7. Logical operators && - Logical AND || - Logical OR ! - Logical NOT By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 7
  • 8. Logical operators Operand 1 Operand 2 Value of the expression Operand 1 && Operand 2 Operand 1 || Operand 2 Non-zero Non-zero 1 1 Non-zero 0 0 1 0 Non-zero 0 1 0 0 0 0 By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 8
  • 9. Assignment operators • Most commonly used binary operator. By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 9 Operator Use Effect += a+=b; a=a+b; -= a-=b; a=a-b; *= a*=b; a=a*b; /= a/=b; a=a/b; %= a%=b; a=a%b;
  • 10. Increment & decrement operator ++m m++ ++ --m m-- -- By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 10
  • 11. Rules for ++ and - - operator Are unary operators and require variables as their operands. When postfix ++ (or --) used with a variable, expression is evaluated with the original value of the variable and then incremented or decremented. When prefix ++v(or --) used, the variable is incremented first and expression is evaluated using the new value of the variable. Precedence and associativity is same as unary + or unary -. By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 11
  • 12. Conditional operator It is a ternary operator. exp1?exp2:exp3 exp1, exp2, exp3 are expressions. x=(a>b)?a:b; By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 12
  • 13. Bitwise operator & • Bitwise AND | • Bitwise OR ^ • Bitwise exclusive OR << • Shift left >> • Shift right By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 13
  • 14. Special operators The comma operator The sizeof operator • Can be used to link the related expressions. • e.g. x=10, y=15 • It is a compile time operator. • Returns the number of bytes the operand occupies. • e.g. m=sizeof(sum); n=sizeof(long int); By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 14
  • 15. Expressions Is a formula Operands are linked together by the use of operators to calculate a value. Operand can be a function, a variable, a constant or an array. e.g. a-b; c+d; etc. By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 15
  • 17. Precedence & associativity of operators By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 17 Precedence rules decide the order in which different operations are applied. Associativity rules decide in which multiple occurrences of the same level operator are applied.
  • 18. Precedence & associativity By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 18 Operator Description Associativity Rank ( ) Function call Left to Right 1 [ ] Array element reference + Unary plus Right to left 2 - Unary minus ++ Increment -- Decrement ! Logical negation ~ One’s complement * Pointer reference(indirection) & Address sizeof Size of an object (type) Type cast(conversion)
  • 19. Precedence & associativity Operator Description Associativity Rank * Multiplication Left to Right 3 / Division % Modulus + Addition Left to right 4 - Subtraction << Left shift Left to right 5 >> Right shift < Less than Left to right 6 <= Less than or equal to > Greater than >= Greater than or equal to == Equality Left to right 7 |= Inequality By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 19
  • 20. Precedence & associativity Operator Description Associativity Rank & Bitwise AND Left to right 8 ^ Bitwise XOR Left to right 9 | Bitwise OR Left to right 10 && Logical AND Left to right 11 || Logical OR Left to right 12 ? : Conditional expression Right to left 13 = Assignment operators Right to left 14 *=, /=, %= +=, -=, &= ^=, |= <<=, >>= , Comma operator Left to right 15 By:SatveerKaur,AssistantProfessor,Khalsa College,Patiala. 20