SlideShare a Scribd company logo
Slide 1
Slide 2
Expressions
In C++, there are many special characters with particular
meanings. Examples include the arithmetic operators:
Relational, Equality, and Logical Operators
Just as with other operators, the relational, equality, and logical operators
have rules of precedence and associativity that determine precisely how
expressions involving them are evaluated. C++ systems use the bool values
true and false to direct the flow of control in the various statement types.
Slide 3
Expressions
Relational, Equality, and Logical Operators
the relational, equality, and logical operators have rules of precedence and
associativity that determine precisely how expressions involving them are
evaluated. C++ systems use the bool values true and false to direct the flow
of control in the various statement types.
Slide 4
Expressions
Logical AND (&&)
p q p && q
T T
T F
F T
F F
Slide 5
Expressions
Logical AND (&&)
p q p && q
T T T
T F F
F T F
F F F
Slide 6
Expressions
Logical OR
p q p || q
T T
T F
F T
F F
Slide 7
Expressions
Logical OR
p q p || q
T T T
T F T
F T T
F F F
Slide 8
Expressions
Logical negation
p !p
T
F
Slide 9
Expressions
Logical negation
p !p
T F
F T
Bitwise Operators
Slide 10
Bitwise operation means convert the number into binary and the carry out the
operation on each bit individually. For example let us take the operation
complement represented by symbol (~). Let me take a number
short A = 42;
A short number is stored in two byte or 16 bits. Therefore,
A when expressed in binary = 00000000 00101010
Complement of A is ~A = 11111111 11010101
Contd...
Slide 11
Bitwise Operators
Slide 12
#include<iostream>
using namespace std;
void main()
{ short A =42;
short B = 12;
int C = A|B;
int D = A<<1;
cout << "C = "<<C <<endl;
cout<< "D = "<<D <<endl;
}
Bitwise Operators
The expected output is as under.
C = 46
D = 84
Slide 13
#include<iostream>
using namespace std;
void main()
{short A =42;
short B = 12;
short C = 24;
short D = A^B; // XOR operator
C <<= 1;
A <<=2; // Shift to left by 2 places and assign
B >>=2 ; // shift right by 2 places and assign
cout<< "A = "<<A<< " tB = "<< B <<endl;
cout << "C = "<<C <<endl;
cout << "D = "<< D <<endl;
}
The expected output is given below.
A = 168 B = 3
C = 48
D = 38
Operators common to C++
Slide 14
Slide 15
Operator Precedence
In C++, you use operators and expressions such as the following:
int MyNumber = 10 * 30 + 20 – 5 * 5 << 2;
The question is, what value would MyNumber contain? The order in which the
various operators are invoked is very strictly specified by the C++ standard.
This order is what is meant by operator precedence.
Slide 16
Slide 17
Assignment and Expressions
C++ provides assignment operators that combine an assignment operator
and some other operator.
C++ also provides increment (++) and decrement (--) operators in both
prefix and postfix form.
Slide 18
Assignment and Expressions
The postfix form behaves differently from the prefix form:
Slide 19
PROGRAMMING WITH VISUAL C++
C++ Relational, Equality, and Logical
Slide 20
PROGRAMMING WITH VISUAL C++
C++ Relational, Equality, and Logical
Slide 21
PROGRAMMING WITH VISUAL C++
C++ Relational, Equality, and Logical
Slide 22
Statements
C++ has a large variety of statement types, including an
expression statement. For example, the assignment
statement in C++ is syntactically an assignment expression
followed by a semicolon.
There are two
statements:
The Simple
Statement
The Compound
Statement
Slide 23
The Compound Statement
The Compound Statement
• A compound statement in C++ is a series of statements
surrounded by braces { and }.
• The body of a C++ function, for example, is always a compound
statement.
Conditional ternary operator ( ? )
Slide 24
The conditional operator evaluates an expression, returning first value if that
expression evaluates to true, and a different one if the expression evaluates as
false. Its syntax is:
condition ? result1 : result2
7==5 ? 4 : 3 // evaluates to 3, since 7 is not equal to 5.
7==5+2 ? 4 : 3 // evaluates to 4, since 7 is equal to 5+2.
5>3 ? a : b // evaluates to the value of a, since 5 is greater than 3.
a>b ? a : b // evaluates to whichever is greater, a or b.
Slide 25
For example:
// conditional operator
#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
a=2;
b=7;
c = (a>b) ? a : b;
cout << c << 'n';
}
In this example, a was 2, and b was 7, so the expression being evaluated (a>b)
was not true, thus the first value specified after the question mark was discarded
in favor of the second value (the one after the colon) which was b (with a value
of 7).
Slide 26
The if and if-else Statements
if and if-else
The general form of an if statement is:
Here is an example of an if statement:
Or another example:
Slide 27
Closely related to the if statement is the if-else statement,
which has the general form
if and if-else
Slide 28
If condition is true, then statement1 is executed and
statement2 is skipped; if condition is false, then
statement1 is skipped and statement2 is executed.
After the if-else statement has been executed, control
passes to the next statement. Consider the next code:
if and if-else
Slide 29
If x < y is true, then min is assigned the value of x;
if x < y is false, min is assigned the value of y. After
the if-else statement is executed, min is printed.
if and if-else
Slide 30
The switch Statement
The switch statement is a multiway conditional
statement generalizing the if-else statement. The
general form of the switch statement is given by
Slide 31
The switch Statement
switch (expression)
{
case constant1:
group-of-statements-1;
break;
case constant2:
group-of-statements-2;
break;
.
.
.
default:
default-group-of-statements
}
Slide 32
The switch Statement
Ex:

More Related Content

PPTX
Operators and Expressions in Java
PPTX
Dti2143 chapter 3 arithmatic relation-logicalexpression
PPT
Unit i intro-operators
PPTX
Operators and Expression
PDF
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
PPT
6 operators-in-c
DOCX
C – operators and expressions
PPTX
Chapter 3: Simplification of Boolean Function
Operators and Expressions in Java
Dti2143 chapter 3 arithmatic relation-logicalexpression
Unit i intro-operators
Operators and Expression
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
6 operators-in-c
C – operators and expressions
Chapter 3: Simplification of Boolean Function

What's hot (20)

PPT
Mesics lecture 4 c operators and experssions
PPTX
Operators and expressions in C++
PDF
Micro Blaze C Reference
PPT
Operation and expression in c++
PDF
Assignment
PPT
Basic c operators
PPTX
Operators-computer programming and utilzation
PDF
Lecture 8 increment_and_decrement_operators
PPTX
Operators and Expressions
DOCX
(Www.entrance exam.net)-tcs placement sample paper 2
PPTX
B sc3 unit 3 boolean algebra
PPT
C tutorial
DOC
Digital logic circuits important question and answers for 5 units
PPT
simplification of boolean algebra
PDF
Types of Operators in C
PDF
Benginning Calculus Lecture notes 7 - exp, log
PDF
Benginning Calculus Lecture notes 6 - implicit differentiation
PPT
Chapter 2 Boolean Algebra (part 2)
PPT
Operators in c language
PPT
Boolean variables r010
Mesics lecture 4 c operators and experssions
Operators and expressions in C++
Micro Blaze C Reference
Operation and expression in c++
Assignment
Basic c operators
Operators-computer programming and utilzation
Lecture 8 increment_and_decrement_operators
Operators and Expressions
(Www.entrance exam.net)-tcs placement sample paper 2
B sc3 unit 3 boolean algebra
C tutorial
Digital logic circuits important question and answers for 5 units
simplification of boolean algebra
Types of Operators in C
Benginning Calculus Lecture notes 7 - exp, log
Benginning Calculus Lecture notes 6 - implicit differentiation
Chapter 2 Boolean Algebra (part 2)
Operators in c language
Boolean variables r010
Ad

Viewers also liked (13)

PPT
Visual Studio 2008 and .NET 3.5 Overview
PPTX
Asbestos is to ban
PDF
Visual Studio 2008 Overview
PPT
Google C++ Testing Framework in Visual Studio 2008
PPTX
Intro to visual studio 2008
PPTX
Presentation on Visual Studio
PPT
Visual Studio IDE
PPTX
Introduction to Visual studio 2012
PPTX
Visual Basic .NET
PDF
Introduccion a Visual Studio .NET
PPTX
Basic controls of Visual Basic 6.0
PPT
Introduction to visual basic programming
PPT
Visual basic ppt for tutorials computer
Visual Studio 2008 and .NET 3.5 Overview
Asbestos is to ban
Visual Studio 2008 Overview
Google C++ Testing Framework in Visual Studio 2008
Intro to visual studio 2008
Presentation on Visual Studio
Visual Studio IDE
Introduction to Visual studio 2012
Visual Basic .NET
Introduccion a Visual Studio .NET
Basic controls of Visual Basic 6.0
Introduction to visual basic programming
Visual basic ppt for tutorials computer
Ad

Similar to 2621008 - C++ 2 (20)

PPS
C programming session 02
PPT
Control structure and Looping statements
PPS
02 iec t1_s1_oo_ps_session_02
PDF
Programming C Part 02
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PDF
Programming for Problem Solving
PPTX
C operators
PPTX
COM1407: C Operators
PDF
Python Unit 3 - Control Flow and Functions
DOCX
Programming Fundamentals lecture 7
PPTX
11operator in c#
PPTX
C programming(Part 1)
PPTX
Computer programming 2 Lesson 7
PPT
Java Programmin: Selections
PPT
Fundamentals of Programming Chapter 5
PDF
Python : basic operators
PPS
C programming session 02
PPT
6 operators-in-c
PPTX
C Operators and Control Structures.pptx
PPTX
additional.pptx
C programming session 02
Control structure and Looping statements
02 iec t1_s1_oo_ps_session_02
Programming C Part 02
Lecture 2 C++ | Variable Scope, Operators in c++
Programming for Problem Solving
C operators
COM1407: C Operators
Python Unit 3 - Control Flow and Functions
Programming Fundamentals lecture 7
11operator in c#
C programming(Part 1)
Computer programming 2 Lesson 7
Java Programmin: Selections
Fundamentals of Programming Chapter 5
Python : basic operators
C programming session 02
6 operators-in-c
C Operators and Control Structures.pptx
additional.pptx

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Hybrid model detection and classification of lung cancer
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
TLE Review Electricity (Electricity).pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
project resource management chapter-09.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Tartificialntelligence_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
A Presentation on Touch Screen Technology
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A comparative analysis of optical character recognition models for extracting...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Hybrid model detection and classification of lung cancer
Group 1 Presentation -Planning and Decision Making .pptx
TLE Review Electricity (Electricity).pptx
DP Operators-handbook-extract for the Mautical Institute
A novel scalable deep ensemble learning framework for big data classification...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
project resource management chapter-09.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Programs and apps: productivity, graphics, security and other tools
Tartificialntelligence_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Enhancing emotion recognition model for a student engagement use case through...
A comparative study of natural language inference in Swahili using monolingua...
A Presentation on Touch Screen Technology
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Zenith AI: Advanced Artificial Intelligence
A comparative analysis of optical character recognition models for extracting...

2621008 - C++ 2

  • 2. Slide 2 Expressions In C++, there are many special characters with particular meanings. Examples include the arithmetic operators: Relational, Equality, and Logical Operators Just as with other operators, the relational, equality, and logical operators have rules of precedence and associativity that determine precisely how expressions involving them are evaluated. C++ systems use the bool values true and false to direct the flow of control in the various statement types.
  • 3. Slide 3 Expressions Relational, Equality, and Logical Operators the relational, equality, and logical operators have rules of precedence and associativity that determine precisely how expressions involving them are evaluated. C++ systems use the bool values true and false to direct the flow of control in the various statement types.
  • 4. Slide 4 Expressions Logical AND (&&) p q p && q T T T F F T F F
  • 5. Slide 5 Expressions Logical AND (&&) p q p && q T T T T F F F T F F F F
  • 6. Slide 6 Expressions Logical OR p q p || q T T T F F T F F
  • 7. Slide 7 Expressions Logical OR p q p || q T T T T F T F T T F F F
  • 10. Bitwise Operators Slide 10 Bitwise operation means convert the number into binary and the carry out the operation on each bit individually. For example let us take the operation complement represented by symbol (~). Let me take a number short A = 42; A short number is stored in two byte or 16 bits. Therefore, A when expressed in binary = 00000000 00101010 Complement of A is ~A = 11111111 11010101 Contd...
  • 12. Slide 12 #include<iostream> using namespace std; void main() { short A =42; short B = 12; int C = A|B; int D = A<<1; cout << "C = "<<C <<endl; cout<< "D = "<<D <<endl; } Bitwise Operators The expected output is as under. C = 46 D = 84
  • 13. Slide 13 #include<iostream> using namespace std; void main() {short A =42; short B = 12; short C = 24; short D = A^B; // XOR operator C <<= 1; A <<=2; // Shift to left by 2 places and assign B >>=2 ; // shift right by 2 places and assign cout<< "A = "<<A<< " tB = "<< B <<endl; cout << "C = "<<C <<endl; cout << "D = "<< D <<endl; } The expected output is given below. A = 168 B = 3 C = 48 D = 38
  • 14. Operators common to C++ Slide 14
  • 15. Slide 15 Operator Precedence In C++, you use operators and expressions such as the following: int MyNumber = 10 * 30 + 20 – 5 * 5 << 2; The question is, what value would MyNumber contain? The order in which the various operators are invoked is very strictly specified by the C++ standard. This order is what is meant by operator precedence.
  • 17. Slide 17 Assignment and Expressions C++ provides assignment operators that combine an assignment operator and some other operator. C++ also provides increment (++) and decrement (--) operators in both prefix and postfix form.
  • 18. Slide 18 Assignment and Expressions The postfix form behaves differently from the prefix form:
  • 19. Slide 19 PROGRAMMING WITH VISUAL C++ C++ Relational, Equality, and Logical
  • 20. Slide 20 PROGRAMMING WITH VISUAL C++ C++ Relational, Equality, and Logical
  • 21. Slide 21 PROGRAMMING WITH VISUAL C++ C++ Relational, Equality, and Logical
  • 22. Slide 22 Statements C++ has a large variety of statement types, including an expression statement. For example, the assignment statement in C++ is syntactically an assignment expression followed by a semicolon. There are two statements: The Simple Statement The Compound Statement
  • 23. Slide 23 The Compound Statement The Compound Statement • A compound statement in C++ is a series of statements surrounded by braces { and }. • The body of a C++ function, for example, is always a compound statement.
  • 24. Conditional ternary operator ( ? ) Slide 24 The conditional operator evaluates an expression, returning first value if that expression evaluates to true, and a different one if the expression evaluates as false. Its syntax is: condition ? result1 : result2 7==5 ? 4 : 3 // evaluates to 3, since 7 is not equal to 5. 7==5+2 ? 4 : 3 // evaluates to 4, since 7 is equal to 5+2. 5>3 ? a : b // evaluates to the value of a, since 5 is greater than 3. a>b ? a : b // evaluates to whichever is greater, a or b.
  • 25. Slide 25 For example: // conditional operator #include <iostream> using namespace std; int main () { int a,b,c; a=2; b=7; c = (a>b) ? a : b; cout << c << 'n'; } In this example, a was 2, and b was 7, so the expression being evaluated (a>b) was not true, thus the first value specified after the question mark was discarded in favor of the second value (the one after the colon) which was b (with a value of 7).
  • 26. Slide 26 The if and if-else Statements if and if-else The general form of an if statement is: Here is an example of an if statement: Or another example:
  • 27. Slide 27 Closely related to the if statement is the if-else statement, which has the general form if and if-else
  • 28. Slide 28 If condition is true, then statement1 is executed and statement2 is skipped; if condition is false, then statement1 is skipped and statement2 is executed. After the if-else statement has been executed, control passes to the next statement. Consider the next code: if and if-else
  • 29. Slide 29 If x < y is true, then min is assigned the value of x; if x < y is false, min is assigned the value of y. After the if-else statement is executed, min is printed. if and if-else
  • 30. Slide 30 The switch Statement The switch statement is a multiway conditional statement generalizing the if-else statement. The general form of the switch statement is given by
  • 31. Slide 31 The switch Statement switch (expression) { case constant1: group-of-statements-1; break; case constant2: group-of-statements-2; break; . . . default: default-group-of-statements }
  • 32. Slide 32 The switch Statement Ex: