SlideShare a Scribd company logo
CSC240
INTRODUCTION TO PROGRAMMING – I
Mr. Dilawar
Lecturer,
Department of Computer Science,
Jahan University
Kabul, Afghanistan.
Previous Lecture Outline
• Variables
• Datatypes
• Declaration and Initialization of Variable
• Constants
• Defining and Using Constants
Lecture Outline
• Operators and Expressions
• Order of Precedence
• Statements and its Types
Operators
• A set of symbols that are used to perform an operation on values.
• C++ provides rich amount of operators such as
• Assignment and arithmetic operators
• Increment/decrement and arithmetic assignment operators
• Relational and comparison operations
• Logical and conditional operators
• Bitwise operators
• Manipulators and other miscellaneous operators
Assignment Operator
• This operator is used for assigning a
value to a variable.
• Assignment operator is =.
• Assigning the value/placing the value
in memory location – destructive and
reading back is called non-destructive.
int a, b, c = 10;
a = 25;
b = a;
Arithmetic Operators
• These operators are used to perform
arithmetic operations on the data such
as addition, subtraction, multiplication,
division and modulo operations.
• They can operate on both variables
and constants.
int a, b, c = 10;
a = 25;
c = a;
b = a + b;
// b = a – b;
// b = a * b;
Arithmetic Assignment Operators
• These operators are used to modify
the current value of a variable by
performing an operation on it.
• Arithmetic operation
• Assignment operation
• Arithmetic assignment operators are
+=, -=, *=, and /=.
int a, b, c = 10;
a = 50;
a += 40; //a = 90
b = 90;
B -= 40; //50;
Arithmetic Assignment Operators
• Look at the list below to better understand the concept:
Increment and Decrement Operators
• These operators are used to add or
subtract one value from the current
value of a variable.
• The increment operator is represented
by ++ and the decrement is
represented by --.
• It can be used either as postfix or
prefix notation.
int a = 50, b, c;
b = a + (++a); //prefix
c = a + (a++); //postfix
Relational or Comparison Operators
• These operators are used to show
relation among number.
• Common relational operators are >, <,
>=, <=, ==, and !=.
• The result can be either true (1) or
false (0).
int a = 50, b = 40;
cout<<(a<b); //return 0
cout<<(a>b); //return 1
Logical Operators
• These operators are used to combine
condition within a single statement.
• They are also called compound
operators.
• Logical operators are &&, ||, and !.
int a = 50, b = 40;
cout<<((a<b) && (a <80));
cout<<(a!=20);
Logical Operators
Implementation of AND Logical Operator
Implementation of OR Logical Operator
Conditional or Ternary Operators
• These operators are used to
return a value when a desired
condition is true or false.
• The common conditional
operators are ? And :.
int a = 50;
cout<<((a>10)?”T”:”F”);
Bitwise Operators
• These operators are used modify variables considering the bit
patterns that represent the values they store.
Manipulators
• These operators are used in C++
for formatting output.
• More commonly manipulators
are endl and setw.
• endl is used for line break.
• setw is used to set the width of an
output.
cout<“Welcome to”<<endl;
cout<<“Jahan
University”<<endl;
cout<<setw(8)<<“Name”<<se
tw(20)<<“Fname”<<endl;
Order of Precedence
• The order in which the arithmetic expression is evaluated is called the
order of precedence.
• Also known as hierarchy of operations.
• C++ expressions are performed in the following order:
• All multiplication and divisions are performed first from left to right.
• All additions and subtractions are then performed from left to right.
• If parenthesis are used in expression, the expressions are first computed.
• When parenthesis are used within parenthesis, the expression with
innermost parenthesis is evaluated first.
Order of Precedence
• For example (4-(3*5))+2 is evaluated as follows:
Summery
• Operators and Expressions
• Order of Precedence
• Statements and its Types
Thank You
For your Patience

More Related Content

What's hot

C operators
C operatorsC operators
C operatorsGPERI
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressionsvinay arora
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsAnuja Lad
 
Operators in c language
Operators in c languageOperators in c language
Operators in c languageAmit Singh
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++Shobi P P
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Digvijaysinh Gohil
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
C language operators
C language operatorsC language operators
C language operatorsmarar hina
 

What's hot (18)

C operators
C operatorsC operators
C operators
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
Operators
OperatorsOperators
Operators
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
C language operators
C language operatorsC language operators
C language operators
 
Coper in C
Coper in CCoper in C
Coper in C
 
Relational operators
Relational operatorsRelational operators
Relational operators
 

Viewers also liked

Viewers also liked (13)

Chapter 01 networking
Chapter 01 networkingChapter 01 networking
Chapter 01 networking
 
Catella e-Crime London2015
Catella e-Crime London2015Catella e-Crime London2015
Catella e-Crime London2015
 
Six Super Simple Productivity Boosters
Six Super Simple Productivity BoostersSix Super Simple Productivity Boosters
Six Super Simple Productivity Boosters
 
Power Point SOP
Power Point SOPPower Point SOP
Power Point SOP
 
Bases curriculares lenguaje 2°
Bases curriculares lenguaje 2°Bases curriculares lenguaje 2°
Bases curriculares lenguaje 2°
 
Pdhpe slideshow pdf
Pdhpe slideshow pdfPdhpe slideshow pdf
Pdhpe slideshow pdf
 
Din cloud launched hosted sql server dinsql
Din cloud launched hosted sql server   dinsqlDin cloud launched hosted sql server   dinsql
Din cloud launched hosted sql server dinsql
 
Characterisation of Neuropeptide Signalling Systems in Learning
Characterisation of Neuropeptide Signalling Systems in LearningCharacterisation of Neuropeptide Signalling Systems in Learning
Characterisation of Neuropeptide Signalling Systems in Learning
 
Trabajo solo CTA 8vo "C"
Trabajo solo CTA 8vo "C"Trabajo solo CTA 8vo "C"
Trabajo solo CTA 8vo "C"
 
Norma la nube
Norma la nubeNorma la nube
Norma la nube
 
Sensores o2 demo
Sensores o2 demoSensores o2 demo
Sensores o2 demo
 
Issuers Story - PCI Congress London 23Jan14
Issuers Story - PCI Congress London 23Jan14Issuers Story - PCI Congress London 23Jan14
Issuers Story - PCI Congress London 23Jan14
 
Ethics at work place
Ethics at work placeEthics at work place
Ethics at work place
 

Similar to Csc240 -lecture_5 (20)

Operators in C#
Operators in C#Operators in C#
Operators in C#
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
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
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
 
Learn C# Programming - Operators
Learn C# Programming - OperatorsLearn C# Programming - Operators
Learn C# Programming - Operators
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators in java script
Operators   in  java scriptOperators   in  java script
Operators in java script
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Theory3
Theory3Theory3
Theory3
 

More from Ainuddin Yousufzai

More from Ainuddin Yousufzai (15)

Chapter04 ip addressing networking
Chapter04 ip addressing networkingChapter04 ip addressing networking
Chapter04 ip addressing networking
 
Chapter 02 topology networking
Chapter 02  topology networkingChapter 02  topology networking
Chapter 02 topology networking
 
Chapter08 internet &amp; multimedia (b)
Chapter08   internet &amp; multimedia (b)Chapter08   internet &amp; multimedia (b)
Chapter08 internet &amp; multimedia (b)
 
Chapter08 internet &amp; multimedia (a)
Chapter08   internet &amp; multimedia (a)Chapter08   internet &amp; multimedia (a)
Chapter08 internet &amp; multimedia (a)
 
Chapter07 io devices
Chapter07   io devicesChapter07   io devices
Chapter07 io devices
 
Chapter06 computer software
Chapter06   computer softwareChapter06   computer software
Chapter06 computer software
 
Chapter05 secondary storage
Chapter05   secondary storageChapter05   secondary storage
Chapter05 secondary storage
 
Chapter04 processor and memory
Chapter04   processor and memoryChapter04   processor and memory
Chapter04 processor and memory
 
Chapter03 number system
Chapter03   number systemChapter03   number system
Chapter03 number system
 
Chapter02 basic computer organization
Chapter02   basic computer organizationChapter02   basic computer organization
Chapter02 basic computer organization
 
Chapter01 introduction to computer
Chapter01   introduction to computerChapter01   introduction to computer
Chapter01 introduction to computer
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
Csc240 -lecture_3
Csc240  -lecture_3Csc240  -lecture_3
Csc240 -lecture_3
 
Csc240 -lecture_2
Csc240  -lecture_2Csc240  -lecture_2
Csc240 -lecture_2
 
Csc240 lecture 1
Csc240   lecture 1Csc240   lecture 1
Csc240 lecture 1
 

Recently uploaded

2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Abhinav Gaur Kaptaan
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 

Recently uploaded (20)

2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 

Csc240 -lecture_5

  • 1. CSC240 INTRODUCTION TO PROGRAMMING – I Mr. Dilawar Lecturer, Department of Computer Science, Jahan University Kabul, Afghanistan.
  • 2. Previous Lecture Outline • Variables • Datatypes • Declaration and Initialization of Variable • Constants • Defining and Using Constants
  • 3. Lecture Outline • Operators and Expressions • Order of Precedence • Statements and its Types
  • 4. Operators • A set of symbols that are used to perform an operation on values. • C++ provides rich amount of operators such as • Assignment and arithmetic operators • Increment/decrement and arithmetic assignment operators • Relational and comparison operations • Logical and conditional operators • Bitwise operators • Manipulators and other miscellaneous operators
  • 5. Assignment Operator • This operator is used for assigning a value to a variable. • Assignment operator is =. • Assigning the value/placing the value in memory location – destructive and reading back is called non-destructive. int a, b, c = 10; a = 25; b = a;
  • 6. Arithmetic Operators • These operators are used to perform arithmetic operations on the data such as addition, subtraction, multiplication, division and modulo operations. • They can operate on both variables and constants. int a, b, c = 10; a = 25; c = a; b = a + b; // b = a – b; // b = a * b;
  • 7. Arithmetic Assignment Operators • These operators are used to modify the current value of a variable by performing an operation on it. • Arithmetic operation • Assignment operation • Arithmetic assignment operators are +=, -=, *=, and /=. int a, b, c = 10; a = 50; a += 40; //a = 90 b = 90; B -= 40; //50;
  • 8. Arithmetic Assignment Operators • Look at the list below to better understand the concept:
  • 9. Increment and Decrement Operators • These operators are used to add or subtract one value from the current value of a variable. • The increment operator is represented by ++ and the decrement is represented by --. • It can be used either as postfix or prefix notation. int a = 50, b, c; b = a + (++a); //prefix c = a + (a++); //postfix
  • 10. Relational or Comparison Operators • These operators are used to show relation among number. • Common relational operators are >, <, >=, <=, ==, and !=. • The result can be either true (1) or false (0). int a = 50, b = 40; cout<<(a<b); //return 0 cout<<(a>b); //return 1
  • 11. Logical Operators • These operators are used to combine condition within a single statement. • They are also called compound operators. • Logical operators are &&, ||, and !. int a = 50, b = 40; cout<<((a<b) && (a <80)); cout<<(a!=20);
  • 12. Logical Operators Implementation of AND Logical Operator Implementation of OR Logical Operator
  • 13. Conditional or Ternary Operators • These operators are used to return a value when a desired condition is true or false. • The common conditional operators are ? And :. int a = 50; cout<<((a>10)?”T”:”F”);
  • 14. Bitwise Operators • These operators are used modify variables considering the bit patterns that represent the values they store.
  • 15. Manipulators • These operators are used in C++ for formatting output. • More commonly manipulators are endl and setw. • endl is used for line break. • setw is used to set the width of an output. cout<“Welcome to”<<endl; cout<<“Jahan University”<<endl; cout<<setw(8)<<“Name”<<se tw(20)<<“Fname”<<endl;
  • 16. Order of Precedence • The order in which the arithmetic expression is evaluated is called the order of precedence. • Also known as hierarchy of operations. • C++ expressions are performed in the following order: • All multiplication and divisions are performed first from left to right. • All additions and subtractions are then performed from left to right. • If parenthesis are used in expression, the expressions are first computed. • When parenthesis are used within parenthesis, the expression with innermost parenthesis is evaluated first.
  • 17. Order of Precedence • For example (4-(3*5))+2 is evaluated as follows:
  • 18. Summery • Operators and Expressions • Order of Precedence • Statements and its Types
  • 19. Thank You For your Patience