Chapter 6: Data Types Lectures # 10.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Names and Bindings.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
ICE1341 Programming Languages Spring 2005 Lecture #9 Lecture #9 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
ISBN Chapter 6 Data Types Character Strings Pattern Matching.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Definitions A data type defines a collection of data.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Primitive Data Types: Numbers Strings Ordinal Types Pointers
2 Systems Architecture, Fifth Edition Chapter Goals Describe numbering systems and their use in data representation Compare and contrast various data.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
String Escape Sequences
CS 355 – Programming Languages
CS 330 Programming Languages 10 / 23 / 2008 Instructor: Michael Eckmann.
CS 330 Programming Languages 10 / 21 / 2008 Instructor: Michael Eckmann.
College of Computer Science and Engineering
ISBN 0-321— Chapter 6 sections 1-4, 9 Primitive Data Types Numbers Strings Ordinal Types Pointers.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Copyright Curt Hill Variables What are they? Why do we need them?
CS 330 Programming Languages 10 / 30 / 2007 Instructor: Michael Eckmann.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
1 CS Programming Languages Class 08 September 19, 2000.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved. 6-2 Chapter 6 Topics Introduction Primitive Data Types.
1 Data Types Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer Types.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1.2 Primitive Data Types and Variables
CS 330 Programming Languages 11 / 01 / 2007 Instructor: Michael Eckmann.
IT11004: Data Representation and Organization Floating Point Representation.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.2 Primitive Data Types Almost all programming languages.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.
CSC 533: Programming Languages Spring 2016
Data Types In Text: Chapter 6.
The Machine Model Memory
CSC 533: Programming Languages Spring 2015
Chapter 6 – Data Types CSCE 343.
Chapter 6 Data Types.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Data Representation Binary Numbers Binary Addition
Chapter 3 Data Storage.
Lecture 16: Introduction to Data Types
Structure of Programming Language
CS 326 Programming Languages, Concepts and Implementation
Instructor : Ahmed Alalawi Slides from Chung –Ta King
EPSII 59:006 Spring 2004.
Concepts of Programming Languages
Concepts of programming languages Names, Bindings, and Scopes
Chapter 6 Data Types.
Complex Data Types One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables Design.
Data.
Chapter 6 Data Types.
Introduction to Abstract Data Types
Chapter 6 Data Types.
Intro to Data Structures and ADTs
IT11004: Data Representation and Organization
CSC 533: Programming Languages Spring 2019
Presentation transcript:

Chapter 6: Data Types Lectures # 10

Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Chapter 6: Data Types 2

Introduction A data type defines a collection of data objects and a set of predefined operations on those objects. More data types makes programming easier but too many data types might be confusing. Chapter 6: Data Types 3

Primitive data types A primitive data type is one that is not defined in terms of other types. Primitive types are a reflection of the underlying hardware: Integer. Floating point. Other primitive types require a little non-hardware support for their implementation. Major categories include: Numeric. Boolean. Character. Chapter 6: Data Types 4

Numeric types: Integer Almost always an exact reflection of hardware. 2s complement binary representation used to store negative integers. C has many different integer types: char, short, int, long. signed and unsigned. Ada allows: SHORT INTEGER, INTEGER, LONG. Java has 4 different integer types: byte, short, int, and long. Chapter 6: Data Types 5

Numeric types: Floating-point Model real numbers, but only as approximations. Languages for scientific use support at least two floating-point types (e.g., float and double) sometimes more. Values are defined in terms of precision and range: Precision is the accuracy of the fractional part. Range is a combination of the range of fractions and exponents. Chapter 6: Data Types 6

Floating-point IEEE floating-point formats: (a) Single precision, (b) Double precision Chapter 6: Data Types 7

Numeric types: Decimal Used mostly for business applications. Stores a fixed number of decimal digits, with the decimal point at a fixed position. Decimal digits are coded (BCD with 2 digits/byte). Example from DCL “Digital Command Language”: PAYRATE FIXED DECIMAL(7,2); Advantage: accuracy. Disadvantages: limited range, wastes memory. Chapter 6: Data Types 8

Boolean Types Simplest of all types. Range of values has only 2 elements, true and false. Introduced in ALGOL 60. Could be represented as a single bit, but most often as a byte (the smallest efficiently addressable cell of memory). C does not include a Boolean type; instead, numeric expressions are used as conditionals. Advantage: readability. Chapter 6: Data Types 9

Character types Character data are stored as numeric codings. ASCII: 8-bit allows 256 characters. Inadequate for global communication. Unicode: 16-bit allows 655,536 characters . Includes characters from most of the world’s natural languages. Java was the first widely-used language to use the Unicode character set. C# and Java Script also support Unicode. Chapter 6: Data Types 10

Character string Types Values are a sequence of characters. Operations on character strings: Assignment, Comparison, Concatenation, Substring, Pattern matching. Chapter 6: Data Types 11

Character string Types: Ada STRING is a type that is predefined as a one-dimensional array of CHARACTER elements: S : STRING(1..10); Operations include: Substring reference: S(1..3) = “Bob”; Concatenation: S = “Bob ” & “Alooga”; Comparison: = , /= , < , <= , > , >= Chapter 6: Data Types 12

Character string Types: C & C++ Not a primitive type. char arrays store character strings. Strings are terminated by ‘\0’  strings have limited dynamic length. The standard library <string.h> includes a collection of string operations, which include: strlen : string length. strcat : string concatenation. strcmp : string comparison. strcpy : string copy. Chapter 6: Data Types 13

Evaluation of character strings Character strings are important to the writability of a language. Dealing with strings as arrays more cumbersome than dealing with a primitive string type. If implemented as a primitive type with static length, they are inexpensive. Dynamic-length strings provide additional flexibility, but are more expensive to implement. Chapter 6: Data Types 14

Character String Length Options Static Length: string (length is specified at the declaration time). FORTRAN 90, Ada, COBOL, Pascal, Java’s String class. Ex in Fortran 90: CHARACTER (LEN = 15) NAME; Limited Dynamic Length: strings can store any number of characters between 0 and maximum (specified by the variables declaration). C and C++. Chapter 6: Data Types 15

Character String Length Options (cont…) Dynamic (no maximum): variables have varying length with no maximum. provides maximum flexibility, but requires of overhead of dynamic storage allocation and deallocation. SNOBOL 4, Perl, JavaScript. Ada supports all three string length options. Chapter 6: Data Types 16