SlideShare a Scribd company logo
1 of 36
Download to read offline
Operators in C/C++
By: Er. Aman Kumar
Operators
• Operators are the special symbols that work
on operand. Like in a + b, a and b are
operands and + is special symbol (operator)
which is working or operating on them.
way2ITech
Types of Operators
way2ITech
Assignment Operator
• Used to assign value to variable. = is
assignment operator.
• NOTE: Value at right side is assigned to left
side variable.
int a = 10;
int b = 55;
b = a;
Value of b will become 10 and value of a will
remain as such. way2ITech
Lvalues and Rvalues
• lvalue : An expression that is an lvalue may
appear as either the left-hand or right-hand
side of an assignment.
way2ITech
• rvalue : An expression that is an rvalue may appear
on the right- but not left-hand side of an assignment.
• Variables are lvalues and so may appear on the left-
hand side of an assignment. Numeric literals are
rvalues and so may not be assigned and can not
appear on the left-hand side.
• Following is a valid statement:
int g = 20;
• But following is not a valid statement and would
generate compile-time error:
• 10 = 20;
way2ITech
Arithmetic operators
way2ITech
way2ITech
Priority of operators
• If 2 operators with same priority come?, then
we will follow left to right rule. Means from
left, which operator comes first, will be
executed. way2ITech
Int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8
• i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8
• i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: *
• i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: /
• i = 1 + 1+ 8 - 2 + 5 / 8 operation: /
• i = 1 + 1 + 8 - 2 + 0 operation: /
• i = 2 + 8 - 2 + 0 operation: +
• i = 10 - 2 + 0 operation: +
• i = 8 + 0 operation: -
• i = 8 operation: +
way2ITech
Int i = 3 / 2 * 4 + 3 / 8 + 3
• i = 3 / 2 * 4 + 3 / 8 + 3
• i = 1 * 4 + 3 / 8 + 3 operation: /
• i = 4 + 3 / 8 + 3 operation: *
• i = 4 + 0 + 3 operation: /
• i = 4 + 3 operation: +
• i = 7 operation: +
way2ITech
Arithmetical Calculations on
Characters
• Arithmetic Calculations on characters can be
done using ASCII codes
way2ITech
way2ITech
Cyclic order in Integers
way2ITech
WAP to enter small case character
and Output upper case character
way2ITech
Compound Arithmetic Assignment
way2ITech
Unary Operators
• These are called as Unary operators as there is
one operator and one operand only. It is two
types:
way2ITech
Rule to solve
• 1. Solve Pre
• 2. Solve Equation (ignore all pre and post and
solve as normal equation)
• 3. Solve Post
way2ITech
Comparison Operators
• They are used to compare value of 2 variables
• These operators deal in true or false. They
return 0 if false and 1 (non zero number) for
true.
way2ITech
• NOTE:
There is difference in x = y and x == y.
x=y assigns value of variable y to variable x.
way2ITech
Logical Operators
• They are used to combine two or multiple
conditions.
• 1. And &&
• 2. OR ||
• 3. NOT !
way2ITech
&& and || are useful in the following programming
situations:
I. When it is to be tested whether a value falls within a
particular range or not.
II. When after testing several conditions the outcome is
only one of the two answers (This problem is often
called yes/no problem or combine multiple
conditions).
• These also work in Boolean Values (True/False).
way2ITech
• Following table shows all the logical operators.
Assume variable A holds 1 and variable B
holds 0, then:
way2ITech
Bitwise Operator
• This work in bits but takes input and gives
Output in decimal form only.
way2ITech
The truth tables for &, |, and ^ are
as follows:
way2ITech
way2ITech
Arithmetic shift
• The two basic types are the
• arithmetic left shift (<<)
• arithmetic right shift (>>)
• For binary numbers it is a bitwise operation that
shifts all of the bits of its operand; every bit in the
operand is simply moved a given number of bit
positions, and the vacant bit-positions are filled in.
• 23<<1 means shift bits of 23 by 1. Sly, 23>>1 means
shift bits of 23 by 1.
way2ITech
way2ITech
Bitwise Complement
• Here we add 1 and then change the sign
• ~N = - (N + 1)
way2ITech
sizeof() operator
• This is used to get size in bytes for datatype,
variable, structures, and union. It returns the
size in bytes.
• sizeof(int) -> 2 (in blue screen TC)
• sizeof(char) -> 1
• sizeof(float) -> 4
way2ITech
way2ITech
Ternary Operator or Conditional
Operator ? :
Syntax
(condition) ? expression 1 : expression 2
way2ITech
way2ITech
way2ITech
way2ITech
8. operators

More Related Content

What's hot

Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and AssociativityNicole Ynne Estabillo
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and StringsIt Academy
 
Python operators
Python operatorsPython operators
Python operatorsnuripatidar
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operatorsAswin Pv
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityAakash Singh
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
 

What's hot (16)

Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Operators
OperatorsOperators
Operators
 
Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and Associativity
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and Strings
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Python operators
Python operatorsPython operators
Python operators
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators
OperatorsOperators
Operators
 
C# Fundamentals - Basics of OOPS - Part 2
C# Fundamentals - Basics of OOPS - Part 2C# Fundamentals - Basics of OOPS - Part 2
C# Fundamentals - Basics of OOPS - Part 2
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
C Operators
C OperatorsC Operators
C Operators
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Relational operators
Relational operatorsRelational operators
Relational operators
 

Viewers also liked

Beauty in my Tile (for grade 8)
Beauty in my Tile (for grade 8)Beauty in my Tile (for grade 8)
Beauty in my Tile (for grade 8)cedrixk
 
Power ups hpm presentation-r2
Power ups   hpm presentation-r2Power ups   hpm presentation-r2
Power ups hpm presentation-r2rickyhwk
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functionsWay2itech
 
Escape sequences
Escape sequencesEscape sequences
Escape sequencesWay2itech
 
Power u ps hpm3300 presentation-r1
Power u ps hpm3300 presentation-r1Power u ps hpm3300 presentation-r1
Power u ps hpm3300 presentation-r1rickyhwk
 
Power u ps hip3300 presentation
Power u ps hip3300 presentationPower u ps hip3300 presentation
Power u ps hip3300 presentationrickyhwk
 
Power u ps hip3300 -500 kva
Power u ps hip3300 -500 kvaPower u ps hip3300 -500 kva
Power u ps hip3300 -500 kvarickyhwk
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)Way2itech
 
Introduction to c_language
Introduction to c_languageIntroduction to c_language
Introduction to c_languageWay2itech
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 

Viewers also liked (14)

Beauty in my Tile (for grade 8)
Beauty in my Tile (for grade 8)Beauty in my Tile (for grade 8)
Beauty in my Tile (for grade 8)
 
Power ups hpm presentation-r2
Power ups   hpm presentation-r2Power ups   hpm presentation-r2
Power ups hpm presentation-r2
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functions
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Escape sequences
Escape sequencesEscape sequences
Escape sequences
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Power u ps hpm3300 presentation-r1
Power u ps hpm3300 presentation-r1Power u ps hpm3300 presentation-r1
Power u ps hpm3300 presentation-r1
 
Kualitas Penduduk
Kualitas PendudukKualitas Penduduk
Kualitas Penduduk
 
Power u ps hip3300 presentation
Power u ps hip3300 presentationPower u ps hip3300 presentation
Power u ps hip3300 presentation
 
Power u ps hip3300 -500 kva
Power u ps hip3300 -500 kvaPower u ps hip3300 -500 kva
Power u ps hip3300 -500 kva
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Diseño en acero y madera clase 2
Diseño en acero y madera clase 2Diseño en acero y madera clase 2
Diseño en acero y madera clase 2
 
Introduction to c_language
Introduction to c_languageIntroduction to c_language
Introduction to c_language
 
10. switch case
10. switch case10. switch case
10. switch case
 

Similar to 8. operators

C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptxZntalemAbebe
 
C++ integer arithmetic
C++ integer arithmeticC++ integer arithmetic
C++ integer arithmeticarvidn
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialHassan A-j
 
Programming techniques
Programming techniquesProgramming techniques
Programming techniquesPrabhjit Singh
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.pptRithwikRanjan
 
Operators in Python
Operators in PythonOperators in Python
Operators in PythonAnusuya123
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of PrecedenceMuhammad Hammad Waseem
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .happycocoman
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATORrricky98
 

Similar to 8. operators (20)

C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptx
 
C++ integer arithmetic
C++ integer arithmeticC++ integer arithmetic
C++ integer arithmetic
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorial
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
Programming techniques
Programming techniquesProgramming techniques
Programming techniques
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Programing techniques
Programing techniquesPrograming techniques
Programing techniques
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
Report on c
Report on cReport on c
Report on c
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Ch4 Expressions
Ch4 ExpressionsCh4 Expressions
Ch4 Expressions
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 

Recently uploaded

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
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
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)

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
 
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
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

8. operators

  • 1. Operators in C/C++ By: Er. Aman Kumar
  • 2. Operators • Operators are the special symbols that work on operand. Like in a + b, a and b are operands and + is special symbol (operator) which is working or operating on them. way2ITech
  • 4. Assignment Operator • Used to assign value to variable. = is assignment operator. • NOTE: Value at right side is assigned to left side variable. int a = 10; int b = 55; b = a; Value of b will become 10 and value of a will remain as such. way2ITech
  • 5. Lvalues and Rvalues • lvalue : An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment. way2ITech
  • 6. • rvalue : An expression that is an rvalue may appear on the right- but not left-hand side of an assignment. • Variables are lvalues and so may appear on the left- hand side of an assignment. Numeric literals are rvalues and so may not be assigned and can not appear on the left-hand side. • Following is a valid statement: int g = 20; • But following is not a valid statement and would generate compile-time error: • 10 = 20; way2ITech
  • 9. Priority of operators • If 2 operators with same priority come?, then we will follow left to right rule. Means from left, which operator comes first, will be executed. way2ITech
  • 10. Int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8 • i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8 • i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: * • i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: / • i = 1 + 1+ 8 - 2 + 5 / 8 operation: / • i = 1 + 1 + 8 - 2 + 0 operation: / • i = 2 + 8 - 2 + 0 operation: + • i = 10 - 2 + 0 operation: + • i = 8 + 0 operation: - • i = 8 operation: + way2ITech
  • 11. Int i = 3 / 2 * 4 + 3 / 8 + 3 • i = 3 / 2 * 4 + 3 / 8 + 3 • i = 1 * 4 + 3 / 8 + 3 operation: / • i = 4 + 3 / 8 + 3 operation: * • i = 4 + 0 + 3 operation: / • i = 4 + 3 operation: + • i = 7 operation: + way2ITech
  • 12. Arithmetical Calculations on Characters • Arithmetic Calculations on characters can be done using ASCII codes way2ITech
  • 14. Cyclic order in Integers way2ITech
  • 15. WAP to enter small case character and Output upper case character way2ITech
  • 17. Unary Operators • These are called as Unary operators as there is one operator and one operand only. It is two types: way2ITech
  • 18. Rule to solve • 1. Solve Pre • 2. Solve Equation (ignore all pre and post and solve as normal equation) • 3. Solve Post way2ITech
  • 19. Comparison Operators • They are used to compare value of 2 variables • These operators deal in true or false. They return 0 if false and 1 (non zero number) for true. way2ITech
  • 20. • NOTE: There is difference in x = y and x == y. x=y assigns value of variable y to variable x. way2ITech
  • 21. Logical Operators • They are used to combine two or multiple conditions. • 1. And && • 2. OR || • 3. NOT ! way2ITech
  • 22. && and || are useful in the following programming situations: I. When it is to be tested whether a value falls within a particular range or not. II. When after testing several conditions the outcome is only one of the two answers (This problem is often called yes/no problem or combine multiple conditions). • These also work in Boolean Values (True/False). way2ITech
  • 23. • Following table shows all the logical operators. Assume variable A holds 1 and variable B holds 0, then: way2ITech
  • 24. Bitwise Operator • This work in bits but takes input and gives Output in decimal form only. way2ITech
  • 25. The truth tables for &, |, and ^ are as follows: way2ITech
  • 27. Arithmetic shift • The two basic types are the • arithmetic left shift (<<) • arithmetic right shift (>>) • For binary numbers it is a bitwise operation that shifts all of the bits of its operand; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in. • 23<<1 means shift bits of 23 by 1. Sly, 23>>1 means shift bits of 23 by 1. way2ITech
  • 29. Bitwise Complement • Here we add 1 and then change the sign • ~N = - (N + 1) way2ITech
  • 30. sizeof() operator • This is used to get size in bytes for datatype, variable, structures, and union. It returns the size in bytes. • sizeof(int) -> 2 (in blue screen TC) • sizeof(char) -> 1 • sizeof(float) -> 4 way2ITech
  • 32. Ternary Operator or Conditional Operator ? : Syntax (condition) ? expression 1 : expression 2 way2ITech