Object Oriented Programming: 9
Expressions and Type Casting in C++
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2
Expressions
• If all operands are integers
– Expression is called an integral expression
• Yields an integral result
• Example: 2 + 3 * 5
• If all operands are floating-point
– Expression is called a floating-point expression
• Yields a floating-point result
• Example: 12.8 * 17.5 - 34.50
3
Mixed Expressions
• Mixed expression:
– Has operands of different data types
– Contains integers and floating-point
• Examples of mixed expressions:
2 + 3.5
6 / 4 + 3.9
5.4 * 2 – 13.6 + 18 / 2
4
Mixed Expressions (continued)
• Evaluation rules:
– If operator has same types of operands
• Evaluated according to the type of the operands
– If operator has both types of operands
• Integer is changed to floating-point
• Operator is evaluated
• Result is floating-point
– Entire expression is evaluated according to
precedence rules
5
Type Conversion (Casting)
• Implicit type coercion: when value of one type
is automatically changed to another type
• Cast operator: provides explicit type
conversion
static_cast<dataTypeName>(expression)
6
Type Conversion (continued)
7
string Type
• Programmer-defined type supplied in
ANSI/ISO Standard C++ library
• Sequence of zero or more characters
• Enclosed in double quotation marks
• Null: a string with no characters
• Each character has relative position in string
– Position of first character is 0
• Length of a string is number of characters in it
– Example: length of "William Jacob" is 13
8
Input
• Data must be loaded into main memory
before it can be manipulated
• Storing data in memory is a two-step process:
– Instruct computer to allocate memory
– Include statements to put data into memory
9
Allocating Memory with Constants and
Variables
• Named constant: memory location whose
content can’t change during execution
• The syntax to declare a named constant is:
• In C++, const is a reserved word
10
Allocating Memory with Constants and
Variables (continued)
• Variable: memory location whose content may
change during execution
• The syntax to declare a named constant is:
11
Putting Data into Variables
• Ways to place data into a variable:
– Use C++’s assignment statement
– Use input (read) statements
Assignment
• Explain the concept of typecasting in C++

More Related Content

PPT
Designing A Syntax Based Retrieval System03
PPTX
What is Data Types and Functions?
PDF
Compilation in c
PPTX
Unit 2 linked list
PDF
Introduction to c++
PPTX
PPTX
if, while and for in Python
PDF
Introduction to c++ ppt
Designing A Syntax Based Retrieval System03
What is Data Types and Functions?
Compilation in c
Unit 2 linked list
Introduction to c++
if, while and for in Python
Introduction to c++ ppt

What's hot (20)

PDF
Data file handling
PDF
C- language Lecture 8
PDF
C++ Version 2
PPTX
An introduction to java programming
PDF
C- language Lecture 4
PPTX
Data Structure and Algorithms –Introduction.pptx
PDF
A08
PDF
C++ version 1
PPTX
Vectors
PDF
Intake 37 ef2
PPTX
Data structure Unit-I Part A
PDF
C- language Lecture 7
PDF
Compiler lec 6_1
DOC
Advance data structure
PDF
C- language Lecture 6
PPT
Data structure
PPTX
Scope - Static and Dynamic
PDF
Python unit 1 part-2
PPTX
Document Classification and Clustering
Data file handling
C- language Lecture 8
C++ Version 2
An introduction to java programming
C- language Lecture 4
Data Structure and Algorithms –Introduction.pptx
A08
C++ version 1
Vectors
Intake 37 ef2
Data structure Unit-I Part A
C- language Lecture 7
Compiler lec 6_1
Advance data structure
C- language Lecture 6
Data structure
Scope - Static and Dynamic
Python unit 1 part-2
Document Classification and Clustering
Ad

Similar to Object oriented programming 9 expressions and type casting in c++ (20)

PPTX
Object oriented programming 10 variables input and output
PPT
Basics of c++ Programming Language
PDF
OOP UNIT 1_removed ppt explaining object.pdf
PPT
Introduction to c
PPTX
Chap_________________1_Introduction.pptx
PPT
Basic concept of c++
PDF
chapter11 - Programming.pdf
PPTX
Object oriented programming 8 basics of c++ programming
PDF
Week02
PPT
PPT slide_chapter 02 Basic element of C++.ppt
PPT
C++.ppt
PPTX
Object oriented programming 12 programming steps in cpp and example
PDF
Basic Elements of C++
PPTX
Nitin Mishra 0301EC201039 Internship PPT.pptx
PPTX
JAVA in Artificial intelligent
PPTX
java in Aartificial intelligent by virat andodariya
PPTX
Cs1123 3 c++ overview
PPTX
C programming language:- Introduction to C Programming - Overview and Importa...
Object oriented programming 10 variables input and output
Basics of c++ Programming Language
OOP UNIT 1_removed ppt explaining object.pdf
Introduction to c
Chap_________________1_Introduction.pptx
Basic concept of c++
chapter11 - Programming.pdf
Object oriented programming 8 basics of c++ programming
Week02
PPT slide_chapter 02 Basic element of C++.ppt
C++.ppt
Object oriented programming 12 programming steps in cpp and example
Basic Elements of C++
Nitin Mishra 0301EC201039 Internship PPT.pptx
JAVA in Artificial intelligent
java in Aartificial intelligent by virat andodariya
Cs1123 3 c++ overview
C programming language:- Introduction to C Programming - Overview and Importa...
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
PPTX
Information and network security 46 digital signature algorithm
PPTX
Information and network security 45 digital signature standard
PPTX
Information and network security 44 direct digital signatures
PPTX
Information and network security 43 digital signatures
PPTX
Information and network security 42 security of message authentication code
PPTX
Information and network security 41 message authentication code
PPTX
Information and network security 40 sha3 secure hash algorithm
PPTX
Information and network security 39 secure hash algorithm
PPTX
Information and network security 38 birthday attacks and security of hash fun...
PPTX
Information and network security 37 hash functions and message authentication
PPTX
Information and network security 35 the chinese remainder theorem
PPTX
Information and network security 34 primality
PPTX
Information and network security 33 rsa algorithm
PPTX
Information and network security 32 principles of public key cryptosystems
PPTX
Information and network security 31 public key cryptography
PPTX
Information and network security 30 random numbers
PPTX
Information and network security 29 international data encryption algorithm
PPTX
Information and network security 28 blowfish
PPTX
Information and network security 27 triple des
Information and network security 47 authentication applications
Information and network security 46 digital signature algorithm
Information and network security 45 digital signature standard
Information and network security 44 direct digital signatures
Information and network security 43 digital signatures
Information and network security 42 security of message authentication code
Information and network security 41 message authentication code
Information and network security 40 sha3 secure hash algorithm
Information and network security 39 secure hash algorithm
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 37 hash functions and message authentication
Information and network security 35 the chinese remainder theorem
Information and network security 34 primality
Information and network security 33 rsa algorithm
Information and network security 32 principles of public key cryptosystems
Information and network security 31 public key cryptography
Information and network security 30 random numbers
Information and network security 29 international data encryption algorithm
Information and network security 28 blowfish
Information and network security 27 triple des

Recently uploaded (20)

PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Microsoft Office 365 Crack Download Free
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PPTX
GSA Content Generator Crack (2025 Latest)
CCleaner 6.39.11548 Crack 2025 License Key
iTop VPN Crack Latest Version Full Key 2025
Patient Appointment Booking in Odoo with online payment
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Advanced SystemCare Ultimate Crack + Portable (2025)
Tech Workshop Escape Room Tech Workshop
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
"Secure File Sharing Solutions on AWS".pptx
Weekly report ppt - harsh dattuprasad patel.pptx
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
Wondershare Recoverit Full Crack New Version (Latest 2025)
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Oracle Fusion HCM Cloud Demo for Beginners
Microsoft Office 365 Crack Download Free
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
GSA Content Generator Crack (2025 Latest)

Object oriented programming 9 expressions and type casting in c++

  • 1. Object Oriented Programming: 9 Expressions and Type Casting in C++ Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 2 Expressions • If all operands are integers – Expression is called an integral expression • Yields an integral result • Example: 2 + 3 * 5 • If all operands are floating-point – Expression is called a floating-point expression • Yields a floating-point result • Example: 12.8 * 17.5 - 34.50
  • 3. 3 Mixed Expressions • Mixed expression: – Has operands of different data types – Contains integers and floating-point • Examples of mixed expressions: 2 + 3.5 6 / 4 + 3.9 5.4 * 2 – 13.6 + 18 / 2
  • 4. 4 Mixed Expressions (continued) • Evaluation rules: – If operator has same types of operands • Evaluated according to the type of the operands – If operator has both types of operands • Integer is changed to floating-point • Operator is evaluated • Result is floating-point – Entire expression is evaluated according to precedence rules
  • 5. 5 Type Conversion (Casting) • Implicit type coercion: when value of one type is automatically changed to another type • Cast operator: provides explicit type conversion static_cast<dataTypeName>(expression)
  • 7. 7 string Type • Programmer-defined type supplied in ANSI/ISO Standard C++ library • Sequence of zero or more characters • Enclosed in double quotation marks • Null: a string with no characters • Each character has relative position in string – Position of first character is 0 • Length of a string is number of characters in it – Example: length of "William Jacob" is 13
  • 8. 8 Input • Data must be loaded into main memory before it can be manipulated • Storing data in memory is a two-step process: – Instruct computer to allocate memory – Include statements to put data into memory
  • 9. 9 Allocating Memory with Constants and Variables • Named constant: memory location whose content can’t change during execution • The syntax to declare a named constant is: • In C++, const is a reserved word
  • 10. 10 Allocating Memory with Constants and Variables (continued) • Variable: memory location whose content may change during execution • The syntax to declare a named constant is:
  • 11. 11 Putting Data into Variables • Ways to place data into a variable: – Use C++’s assignment statement – Use input (read) statements
  • 12. Assignment • Explain the concept of typecasting in C++