SlideShare a Scribd company logo
1 of 16
DATA TYPES
Lesson 8
MANOLO L. GIRON
RMTU
1Structure of Programming Language
DATA TYPES
• A data type defines a collection of data values and a set of
predefined operations on those values.
• Computer programs produce results by manipulating data.
• An important factor in determining the ease with which they
can perform this task is how well the data types available in
the language being used match the objects in the real-world
of the problem being addressed.
2Structure of Programming Language
Numeric Data Types
• Integer
• The most common primitive numeric data type.
• These sizes of integers, and often a few others, are supported by some programming
languages.
• Java includes four signed integer sizes: byte, short, int, and long.
• C++ and C#, include unsigned integer types, which are simply types for integer values
without signs.
• Unsigned types are often used for binary data.
• Signed integer value is represented in a computer by a string of bits, with one of the bits
(typically the leftmost) representing the sign.
3Structure of Programming Language
Numeric Data Types cont.
• Floating-Point
• Floating-point data types model real numbers, but the representations are only approximations
for many real values.
• On most computers, floating point numbers are stored in binary, which exacerbates the problem.
• Floating-point values are represented as fractions and exponents, a form that is borrowed from
scientific notation.
• Most languages include two floating-point types, often called float and double
• The float type is the standard size, usually being stored in four bytes of memory.
• The double type
• is provided for situations where larger fractional parts and/or a larger range of exponents is needed.
• Double-precision variables usually occupy twice as
• much storage as float variables and provide at least twice the number of bits of fraction.
4Structure of Programming Language
Numeric Data Types Cont.
• Decimal
• Decimal data types store a fixed number of decimal digits, with the decimal point at a
fixed position in the value.
• Decimal types have the advantage of being able to precisely store decimal values, at
least those within a restricted range, which cannot be done with floating-point.
• Decimal types are stored very much like character strings, using binary codes for the
decimal digits.
• These are the primary data types for business data processing and are therefore essential
to COBOL. C# and F# also have decimal data types.
5Structure of Programming Language
Numeric Data Types Cont.
• Complex
• Complex values are represented as ordered pairs of floating-point values.
• Some programming languages support a complex data type—for example, Fortran and
Python.
• In Python, the imaginary part of a complex literal is specified by following it with a j or
J—for example, (7 + 3j)
6Structure of Programming Language
Boolean Data Types
• Boolean types are perhaps the simplest of all types.
• Their range of values
• has only two elements: one for TRUE and one for FALSE.
• Boolean types are often used to represent switches or flags in programs.
7Structure of Programming Language
Character Types Data Types
• A character string type is one in which the values consist of sequences of
characters.
• Character string constants are used to label output, and the input and output of all
kinds of data are often done in terms of strings.
• Character string constants are used to label output, and the input and output of all
kinds of data are often done in terms of strings.
• The most common string operations are assignment, catenation, substring
reference, comparison, and pattern matching.
• C and C++ use char arrays to store character strings.
• C++ programmers should use the string class from the standard library, rather than
char arrays and the C string library.
• C# and Ruby include string classes that are similar to those of Java
8Structure of Programming Language
User-Defined Ordinal Data Types
• Enumeration Types
• An enumeration type is one in which all of the possible values, which are named constants, are
provided, or enumerated, in the definition.
• Enumeration types provide a way of defining and grouping collections of named constants, which are
called enumeration constants.
• C# example: enumdays {Mon, Tue, Wed, Thu, Fri, Sat, Sun};
• C and Pascal were the first widely used languages to include an enumeration data type. C++ includes
C’s enumeration types. In C++, we could have the following:
• enumcolors {red, blue, green, yellow, black};
• colors myColor = blue, yourColor = red;
• In ML, enumeration types are defined as new types with datatypedeclarations. For example, we could
have the following:
• datatypeweekdays = Monday | Tuesday | Wednesday | Thursday | Friday 9Structure of Programming Language
Array Data Types
• An array is a homogeneous aggregate of data elements in which an individual
element is identified by its position in the aggregate, relative to the first element.
• In many languages, such as C, C++, Java, Ada, and C#, all of the elements of an
array are required to be of the same type.
• STATIC ARRAY
• FIXED STACK-DYNAMIC ARRAY
• STACK-DYNAMIC ARRAY
• FIXED HEAP-DYNAMIC ARRAY
• HEAP-DYNAMIC ARRAY
10Structure of Programming Language
STATIC ARRAY
• A static array is one in which the subscript ranges are statically bound and
storage allocation is static (done before run time).
• The advantage of static arrays is efficiency:
• No dynamic allocation or de allocation is required.
• The disadvantage is that the storage for the array is fixed for the entire
execution time of the program
11Structure of Programming Language
FIXED STACK-DYNAMIC ARRAY
• A fixed stack-dynamic array is one in which the subscript ranges are statically
bound, but the allocation is done at declaration elaboration time during execution.
• The advantage of fixed stack-dynamic arrays over static arrays is space efficiency.
• A large array in one subprogram can use the same space as a large array in a
different subprogram, as long as both subprograms are not active at the same time.
• The same is true if the two arrays are in different blocks that are not active at the
same time. The disadvantage is the required allocation and de allocation time.
12Structure of Programming Language
STACK-DYNAMIC ARRAY
• A stack-dynamic array is one in which both the subscript ranges and the
storage allocation are dynamically bound at elaboration time.
• Once the subscript ranges are bound and the storage is allocated, however,
they remain fixed during the lifetime of the variable.
• The advantage of stack-dynamic arrays over static and fixed stack-dynamic
arrays is flexibility.
• The size of an array need not be known until the array is about to be used.
13Structure of Programming Language
FIXED HEAP-DYNAMIC ARRAY
• A fixed heap-dynamic array is similar to a fixed stack-dynamic array, in that the
subscript ranges and the storage binding are both fixed after storage is allocated.
• The differences are that both the subscript ranges and storage bindings are done
when the user program requests them during execution, and the storage is allocated
from the heap, rather than the stack.
• The advantage of fixed heap-dynamic arrays is flexibility—the array’s size always fits
the problem.
• The disadvantage is allocation time from the heap, which is longer than allocation
time from the stack.
14Structure of Programming Language
HEAP-DYNAMIC ARRAY
• A heap-dynamic array is one in which the binding of subscript ranges and
storage allocation is dynamic and can change any number of times during the
array’s lifetime.
• The advantage of heap-dynamic arrays over the others is flexibility: Arrays
can grow and shrink during program execution as the need for space
changes.
• The disadvantage is that allocation and de allocation take longer and may
happen many times during execution of the program.
15Structure of Programming Language
REFERENCES
• CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
ROBERT W. SEBESTA
Structure of Programming Language

More Related Content

What's hot

Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)Simran Kaur
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMSkoolkampus
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Krishna Sai
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop pptdaxesh chauhan
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of CompilerPreethi AKNR
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Md. Imran Hossain Showrov
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGSaqib Raza
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLDHAAROUN
 
OOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | IntroductionOOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | IntroductionADITYATANDONKECCSE
 

What's hot (20)

Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
2. pl domain
2. pl domain2. pl domain
2. pl domain
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMS
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
 
c++
 c++  c++
c++
 
java token
java tokenjava token
java token
 
Assemblies
AssembliesAssemblies
Assemblies
 
Analysis modeling
Analysis modelingAnalysis modeling
Analysis modeling
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
 
Java History
Java HistoryJava History
Java History
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 
OOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | IntroductionOOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | Introduction
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 

Similar to 8. data types

Similar to 8. data types (20)

Java platform
Java platformJava platform
Java platform
 
Datatype
DatatypeDatatype
Datatype
 
pl12ch6.ppt
pl12ch6.pptpl12ch6.ppt
pl12ch6.ppt
 
332 ch07
332 ch07332 ch07
332 ch07
 
C language
C languageC language
C language
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
chapter 5.ppt
chapter 5.pptchapter 5.ppt
chapter 5.ppt
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 
Ch6
Ch6Ch6
Ch6
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
6 data types
6 data types6 data types
6 data types
 
Data.ppt
Data.pptData.ppt
Data.ppt
 
12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
INTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c languageINTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c language
 
C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.ppt
 
C programming
C programmingC programming
C programming
 
Java introduction
Java introductionJava introduction
Java introduction
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxAlgorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
 
Java ce241
Java ce241Java ce241
Java ce241
 

More from Zambales National High School

More from Zambales National High School (20)

8. digital integrated circuit
8. digital integrated circuit8. digital integrated circuit
8. digital integrated circuit
 
7. transformer and diode
7. transformer and diode7. transformer and diode
7. transformer and diode
 
5. resistor and capacitor application
5. resistor and capacitor application5. resistor and capacitor application
5. resistor and capacitor application
 
6. transistor
6. transistor6. transistor
6. transistor
 
4. resistor and capacitor
4. resistor and capacitor4. resistor and capacitor
4. resistor and capacitor
 
2. Basic Electronics Circuit
2. Basic Electronics Circuit2. Basic Electronics Circuit
2. Basic Electronics Circuit
 
3. basic electrical and electronic symbol
3. basic electrical and electronic symbol3. basic electrical and electronic symbol
3. basic electrical and electronic symbol
 
11. abstraction and capsulation
11. abstraction and capsulation11. abstraction and capsulation
11. abstraction and capsulation
 
10. sub program
10. sub program10. sub program
10. sub program
 
9. control statement
9. control statement9. control statement
9. control statement
 
7. name binding and scopes
7. name binding and scopes7. name binding and scopes
7. name binding and scopes
 
6. describing syntax and semantics
6. describing syntax and semantics6. describing syntax and semantics
6. describing syntax and semantics
 
5. evolution
5. evolution5. evolution
5. evolution
 
4. processor
4. processor4. processor
4. processor
 
3. criteria
3. criteria3. criteria
3. criteria
 
18. the components of the system unit
18. the components of the system unit18. the components of the system unit
18. the components of the system unit
 
17. software for home, personal, and educational
17. software for home, personal, and educational17. software for home, personal, and educational
17. software for home, personal, and educational
 
16. graphics and multimedia software
16. graphics and multimedia software16. graphics and multimedia software
16. graphics and multimedia software
 
15. business software
15. business software15. business software
15. business software
 
14. application software
14. application software14. application software
14. application software
 

Recently uploaded

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...nhezmainit1
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 

Recently uploaded (20)

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

8. data types

  • 1. DATA TYPES Lesson 8 MANOLO L. GIRON RMTU 1Structure of Programming Language
  • 2. DATA TYPES • A data type defines a collection of data values and a set of predefined operations on those values. • Computer programs produce results by manipulating data. • An important factor in determining the ease with which they can perform this task is how well the data types available in the language being used match the objects in the real-world of the problem being addressed. 2Structure of Programming Language
  • 3. Numeric Data Types • Integer • The most common primitive numeric data type. • These sizes of integers, and often a few others, are supported by some programming languages. • Java includes four signed integer sizes: byte, short, int, and long. • C++ and C#, include unsigned integer types, which are simply types for integer values without signs. • Unsigned types are often used for binary data. • Signed integer value is represented in a computer by a string of bits, with one of the bits (typically the leftmost) representing the sign. 3Structure of Programming Language
  • 4. Numeric Data Types cont. • Floating-Point • Floating-point data types model real numbers, but the representations are only approximations for many real values. • On most computers, floating point numbers are stored in binary, which exacerbates the problem. • Floating-point values are represented as fractions and exponents, a form that is borrowed from scientific notation. • Most languages include two floating-point types, often called float and double • The float type is the standard size, usually being stored in four bytes of memory. • The double type • is provided for situations where larger fractional parts and/or a larger range of exponents is needed. • Double-precision variables usually occupy twice as • much storage as float variables and provide at least twice the number of bits of fraction. 4Structure of Programming Language
  • 5. Numeric Data Types Cont. • Decimal • Decimal data types store a fixed number of decimal digits, with the decimal point at a fixed position in the value. • Decimal types have the advantage of being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point. • Decimal types are stored very much like character strings, using binary codes for the decimal digits. • These are the primary data types for business data processing and are therefore essential to COBOL. C# and F# also have decimal data types. 5Structure of Programming Language
  • 6. Numeric Data Types Cont. • Complex • Complex values are represented as ordered pairs of floating-point values. • Some programming languages support a complex data type—for example, Fortran and Python. • In Python, the imaginary part of a complex literal is specified by following it with a j or J—for example, (7 + 3j) 6Structure of Programming Language
  • 7. Boolean Data Types • Boolean types are perhaps the simplest of all types. • Their range of values • has only two elements: one for TRUE and one for FALSE. • Boolean types are often used to represent switches or flags in programs. 7Structure of Programming Language
  • 8. Character Types Data Types • A character string type is one in which the values consist of sequences of characters. • Character string constants are used to label output, and the input and output of all kinds of data are often done in terms of strings. • Character string constants are used to label output, and the input and output of all kinds of data are often done in terms of strings. • The most common string operations are assignment, catenation, substring reference, comparison, and pattern matching. • C and C++ use char arrays to store character strings. • C++ programmers should use the string class from the standard library, rather than char arrays and the C string library. • C# and Ruby include string classes that are similar to those of Java 8Structure of Programming Language
  • 9. User-Defined Ordinal Data Types • Enumeration Types • An enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition. • Enumeration types provide a way of defining and grouping collections of named constants, which are called enumeration constants. • C# example: enumdays {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; • C and Pascal were the first widely used languages to include an enumeration data type. C++ includes C’s enumeration types. In C++, we could have the following: • enumcolors {red, blue, green, yellow, black}; • colors myColor = blue, yourColor = red; • In ML, enumeration types are defined as new types with datatypedeclarations. For example, we could have the following: • datatypeweekdays = Monday | Tuesday | Wednesday | Thursday | Friday 9Structure of Programming Language
  • 10. Array Data Types • An array is a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate, relative to the first element. • In many languages, such as C, C++, Java, Ada, and C#, all of the elements of an array are required to be of the same type. • STATIC ARRAY • FIXED STACK-DYNAMIC ARRAY • STACK-DYNAMIC ARRAY • FIXED HEAP-DYNAMIC ARRAY • HEAP-DYNAMIC ARRAY 10Structure of Programming Language
  • 11. STATIC ARRAY • A static array is one in which the subscript ranges are statically bound and storage allocation is static (done before run time). • The advantage of static arrays is efficiency: • No dynamic allocation or de allocation is required. • The disadvantage is that the storage for the array is fixed for the entire execution time of the program 11Structure of Programming Language
  • 12. FIXED STACK-DYNAMIC ARRAY • A fixed stack-dynamic array is one in which the subscript ranges are statically bound, but the allocation is done at declaration elaboration time during execution. • The advantage of fixed stack-dynamic arrays over static arrays is space efficiency. • A large array in one subprogram can use the same space as a large array in a different subprogram, as long as both subprograms are not active at the same time. • The same is true if the two arrays are in different blocks that are not active at the same time. The disadvantage is the required allocation and de allocation time. 12Structure of Programming Language
  • 13. STACK-DYNAMIC ARRAY • A stack-dynamic array is one in which both the subscript ranges and the storage allocation are dynamically bound at elaboration time. • Once the subscript ranges are bound and the storage is allocated, however, they remain fixed during the lifetime of the variable. • The advantage of stack-dynamic arrays over static and fixed stack-dynamic arrays is flexibility. • The size of an array need not be known until the array is about to be used. 13Structure of Programming Language
  • 14. FIXED HEAP-DYNAMIC ARRAY • A fixed heap-dynamic array is similar to a fixed stack-dynamic array, in that the subscript ranges and the storage binding are both fixed after storage is allocated. • The differences are that both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap, rather than the stack. • The advantage of fixed heap-dynamic arrays is flexibility—the array’s size always fits the problem. • The disadvantage is allocation time from the heap, which is longer than allocation time from the stack. 14Structure of Programming Language
  • 15. HEAP-DYNAMIC ARRAY • A heap-dynamic array is one in which the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array’s lifetime. • The advantage of heap-dynamic arrays over the others is flexibility: Arrays can grow and shrink during program execution as the need for space changes. • The disadvantage is that allocation and de allocation take longer and may happen many times during execution of the program. 15Structure of Programming Language
  • 16. REFERENCES • CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION ROBERT W. SEBESTA Structure of Programming Language