SlideShare a Scribd company logo
1 of 47
Data Types
             (Chapter 6)
Name:                            ID:
AHMAD ARAFAT BIN MOHD ALI       1091105499
NUR FAIRUZ BINTI MUHAMED ASRI   1091104133
SYUHAIDA AHMAD ARIFFIN          1101108762
SURAYA NURAIN BINTI KALID       1101109398
• What is data type?

      int x = 5;
Boolean
Character
- Charter types are stored as numeric codings
They are used to represent switched and flags in programs.
- (ASCII / Unicode).
                                                Complex
                                                                        Single Precision
                        Numeric               Floating Point
                         Types                                          Double Precision

                                                 Decimal


Floating Point:                                     Integer
1) Single Precision:
 Primitive Data Types       Boolean                                    Integer
               Decimal:
Complex Type:                                                           Bytes
               Example: (in C#) decimal myMoney = 300.5m;                               Java
Example (in Phyton):
2) Double Precision:                                                     Long
(7+3j)                                             ASCII
               Advantage: Greater precision and a smaller range compared to Floating Point
                             Character
                                                                        Short
Programming Languages that support Complex Type: Unicode
Fortran, Phyton
Limited Dynamic String Strings
 Dynamic Length Length
 Static Length String:          Design Issues               1) Static or dynamic?
--The length canvarious lengthset whenmaximum. is created Special Type of character
  String strings can store any number of chars between2)
 -Allowsvariablesbe static and with no the string            zero and the maximum
 -Requires ‘0’ is used to indicate the end of string’s characters (used primitive types?
                                                                array or by C)
-Delimiter the overhead of dynamic storage allocation and deallocation but provides
 flexibility
 Example Fotran-90: Character (LEN=15) name;
                                          Comparison
                                                               Assignment
Example: JavaScript and Perl

                               Operations                     Concatenation
                                on String
    Character String                                            Substring
         Types

                                              Copy               Length


Example:
Example:
Assume s=“good”, t=“bye”
Assume s=“good”, t=“bye”
Assume s=“good”, t=“bye”
                                                                Static Length String
strcpy(x,s); = //return false String length
if (s.equals(t)) “goo”;
strlen(s)=3;,‘hello’-
Strcat(s,t)=goodbye
 Char x *+ =
Subs(s1,0,2)                                                       (Fixed Length)

                                 Options                         Limited Dyna mic
x=good                                                             Length String

                                                                  Dynamic Length
                                                                      String
User-Defined
                                    Ordinal Types



      Enumeration                                                Subrange
         Types                                                     Types



2) Enumeration Types - provides a of defining and grouping collections of named
1) Subrange Types - provides a way way of defining and grouping collections of named
constant.
    constant.

Example In Ada:
             C#:
type Days is (Mon, Tue, Wed Thu, Fri, Sat, Sun);
enum days {Mon, Tue,Wed, Thu, Fri, Sat, Sun};
subtype Weekdays is Days range Mon..Fri;
subtype Index
Advantage: is Integer range 1..100;
a) Readibility – Named values are easily recognized
Advantages:
b) Realibility – No arithmetic operations are legal on enumeration type
a) Enhance Readibility – variable of subtype can store only certain range.
b) Realibility (use integer values to represent enumeration to assign
Example in C– because a compiler can detect error if we try type): value to a specified
subrange value.
int red = 0, blue = 1
Categories Of Array
Categories of      Range of           Storage Bindings   Advantages      Example
Array              subscripts

1. Static Array    Statically bound   Static (done       Execution       Fortran-77, C, C++
                                      before runtime)    efficiency
2. Fixed Stack     Statically bound   Done during        Storage space   C , C++
Dynamic Array                         execution          can be reused
3. Stack Dynamic   Dynamic            Dynamic            Flexibility     Ada
Array
4. Fixed Heap      Fixed after        Fixed after        Flexibility     Fortran 95, C,
Dynamic Array      storage is         storage is                         C++, Java, C#
                   allocated          allocated
                   -done when         -allocated from
                   user program       the heap
                   requests during
                   execution
5. Heap Dynamic    Dynamic            Dynamic            Flexibility     C#, Java,
Array                                                                    JavaScript,
                                                                         Python, Ruby
Array Initialization

Programming Language             How it is initialize?

1. Fortran 95                    Integer, Dimension (3) :: List = (/0, 5, 5 /)

2. C and C++                     int list [ ] = {4, 5, 7, 83};
                                 int list [3] = {3, 5, 7};
                                 char name * + = “freddie”;

3. Java                          String[ + names = *“Bob”, “Jake”+;

          Array Operation

Programming Language                   Example Operation
Fortran 95                             ( + ) operator
                                       Give result sum of element
                                       pairs of the two arrays.
Rectangular Array       Jagged Array




Language supported:   Language supported:
 Fortran              Java
 Ada                  C
 C#                   C++
                       C#
[0] [1]          [2]
[0] 2 6              10
[1] 3 5              8
                                 Implementation Of Array Types
[2] 12 1             7
          Row Major Order
                                                           Column Major Order
          Int num[3][3];
                                                           Int num[3][3];
            [0]            [1]     [2]                     [1]      [2]     [3]
    [0]         2          6       10               [1]     2       6       10

    [1]         3          5       8                [2]     3       5       8

    [2]         12         1       7                [3]     12      1       7


     2      6        10 3 5 8 12 1 7
                                                          2 3    12 6 5 1 10 8 7
          Language : C, Pascal, Java                      Language : Fortran
Record type

What is record?     Record is an aggregate of data elements
                     in which the individual elements are identified
                    by names and accessed through offset
                    from the beginning of the structure.
Differences between Record and Array

Record                         Array
Fields are referenced by using Fields are referenced by
their names                     indices
Use when the collection of      Use when all the data
data objects is heterogeneous elements have same type and
and fields are not processed in are processed in same way.
same way.
Fields of records are not      Processing of array elements is
processed in any particular    usually done by in a sequential
sequential order.              order
Operations on Records
Programming      Operation
Languages
Ada              1. Allow comparison
                  = (equality)
                  /= (inequality)
                 2. Initialize with aggregate literals.
COBOL            1. Provide
                 MOVE CORRESPONDING
                 Example:
                 MOVE CORRESPONDING INPUT_RECORD TO OUTPUT_RECORD.
                 01 INPUT_RECORD.
                    02 NAME.
                        05 LAST             PICTURE IS X (20).
                        05 MIDDLE           PICTURE IS X (15).
                        05 FIRST            PICTURE IS X (20) .
                    02 EMPLOYEE_NUMBER      PICTURE IS 9 (10).
                    02 HOURS_WORKED          PICTURE IS 99.

                 01 OUTPUT_RECORD.
                     02 NAME.
                        05 LAST               PICTURE IS X (20).
                        05 MIDDLE             PICTURE IS X (15).
                        05 FIRST              PICTURE IS X (20) .
                    02 EMPLOYEE_NUMBER        PICTURE IS 9 (10).
                    02 GROSS_PAY              PICTURE IS 999V999.
                   02 NET_PAY                 PICTURE IS 999V999.
Language   Name Type Equivalent   Structure Type Equivalent
Ada        Works well             More rigid
C          Works well             Works well
C++        Works well             Works well
Fortran    Cannot use             Works well
COBOL      Cannot use             Works well
6.8 Union Type
Introduction

•    A union is a type whose variables are allowed to store different type
     values at different times during execution.
•    Example:
              union foo {
                                                           union foo x;
                 int a;
                                                          x.a = 3; // OK
                 char b;                                     x.b = 'c';
                 } foo;                        // NO! this affects the value of x.a!
    //can’t use both a and b at the
              same time                      Prints out 99,99

           struct bar {                      struct bar y;
              int a;                         y.a = 3;      // OK
              char b;                        y.b = 'c';     // OK
              } bar;
//can use a and b simultaneously             Prints out 387427, 99
6.8.2 Discriminated versus free unions
                                            Type of Unions




           Discriminated
                                                                 Free Unions
              Unions


   It has a type checking support for unions                 Fortran, C, and C++ provide
     require that each union include a type
                                                               union constructs in which
                    indicator.
  The first language to provide discriminated
                                                              there is no language support
union was ALGOL 68 which is later supported                  for type checking therefore it
                    by ADA.                                     is unsafe to use in these
                                                                        languages.



   Unconstrained                  Constrained
  Variant Variable               Variant Variable
6.8.3 Ada union type
                               Ada union type


   Constrained variant                                 Unconstrained variant
        variable                                             records


                                       Allow the values of their variants to change types
Allows the user to specify             during execution. The type can only be changed
    variables of a variant             only by assigning the entire record, including the
 record type that will store                             discriminant.
  only one of the possible
                                       This disallows inconsisient records because if the
 type values in the variant.               newly assigned record is a constant data
  In this way, the user can             aggregate, the value of the tag and the type of
  tell the system when the             variant can be statically checked for consistency.
    type checking can be
  static, because we know              If the assigned value is a variable, its consistency
that type checking must be             was guaranteed when it was assigned, so the new
           dynamic.                     value of the variable now being assigned is sure
                                                        to be consistent.
How does union
                                   implemented in              At compile time,
                                    programming                the complete
                                     languages?                description of each
                                                               variant must be
Use the same address                                           stored by creating a
for every variant.                                             case table.




                                            In Ada language, the
          Sufficient storage for            exact amount of
          the largest variant is            storage can be used
          allocated.                        because there is no
                                            variation.
The descriptor for this type could have the form shown in the
figure below:
6.9 Pointer and reference type
Introduction
• A pointer type variable has a range of values that
  consists of memory addresses and a special value, nil
• Provide the power of indirect addressing
• Provide a way to manage dynamic memory
• A pointer can be used to access a location in the area
  where storage is dynamically created (usually called a
  heap)
6.9.2 Pointer operations
• Language that provide pointer has two fundamental
  operations: assignment and dereferencing
• Assignment is used to set a pointer variable’s value to
  some useful address
• Dereferencing yields the value stored at the location
  represented by the pointer’s value
   – Dereferencing can be explicit or implicit
   – C++ uses an explicit operation via * (asterisk)
     j = *ptr
     sets j to the value located at ptr
Problems with pointer


    Dangling                                  lost heap-
    pointers                                  dynamic
    (dangerous)                               variable



A pointer points                      An allocated heap-dynamic
   to a heap-                         variable that is no longer
dynamic variable                      accessible to the user
                                      program (often called
 that has been
                                      garbage)
  deallocated.


                                1.   Pointer p1 is set to point to a newly
                                     created heap-dynamic variable

                                2.   Pointer p1 is later set to point to another
                                     newly created heap-dynamic variable

                                3.   The first heap –dynamic variable is now
                                     inaccessible (memory leakage).
Pointers



           Ada                                                        C++



•   It is called access
    types                     •   Extremely flexible but must be used with care
•   Some dangling             •   Pointers can point at any variable regardless of
    pointers are                  when it was allocated
    disallowed because        •   Used for dynamic storage management and
    dynamic objects can           addressing
    be automatically de-      •   Pointer arithmetic is possible
    allocated at the end of   •   Explicit dereferencing and address-of operators
    pointer's type scope      •   Domain type need not be fixed (void *)
•   The lost heap-            •   void * can point to any type and can be type
    dynamic variable              checked (cannot be de-referenced)
    problem is not
    eliminated by Ada.
6.9.6 Reference types

• C++ includes a special kind of pointer type called a
  reference type that is used primarily for formal
  parameters
   – Advantages of both pass-by-reference and pass-by-value
• Java extends C++’s reference variables and allows
  them to replace pointers entirely
   – References refer to call instances
• C# includes both the references of Java and the
  pointers of C++
6.9.7 Evaluation of pointers

• Dangling pointers and dangling objects are the
  same problems as is heap management
• Pointers are like goto's--they widen the range
  of cells that can be accessed by a variable
• Pointers or references are necessary for
  dynamic data structures--so we can't design a
  language without them.
Implementation of pointers and reference type



Representation of                Solutions to dangling
  pointers and                                                             Heap management
                                        pointers
  referencces

                      Tombstone: extra heap cell that is a pointer     A very complex run-time
•   Large             to the heap-dynamic variable                     process
    computers
    use single
                             The actual pointer variable points only   Single-size cells vs. variable-
                             at tombstones                             size cells
    values
                             When heap-dynamic variable de-
•   Intel                                                              Two approaches to reclaim
                             allocated, tombstone remains but set
    microproce                                                         garbage
                             to nil
    ssors use                                                                Reference counters
    segment                  Costly in time and space
                                                                             (eager approach):
    and offset         Locks-and-keys: Pointer values are
                      represented as (key, address) pairs                    reclamation is gradual
                             Heap-dynamic variables are                      Garbage collection (lazy
                             represented as variable plus cell for           approach): reclamation
                             integer lock value                              occurs when the list of
                             When heap-dynamic variable                      variable space becomes
                             allocated, lock value is created and            empty
                             placed in lock cell and key cell of
                             pointer
Reference counter
• Reference counters: maintain a counter in every cell
  that store the number of pointers currently pointing
  at the cell
   – Disadvantages: space required, execution time required,
     complications for cells connected circularly
   – Advantage: it is intrinsically incremental its actions are
     interleaved with those of the applicasion so it never causes
     significant delays in the execution of the application.
Garbage collection
• The run-time system allocates storage cells as requested
  and disconnects pointers from cells as necessary; garbage
  collection then begins
   – Every heap cell has an extra bit used by collection algorithm
   – All cells initially set to garbage
   – All pointers traced into heap, and reachable cells marked as not
     garbage
   – All garbage cells returned to list of available cells
   – Disadvantages: when you need it most, it works worst (takes
     most time when program needs most of cells in heap)
Marking algorithm
Variable sized cells
• All the difficulties of single-size cells plus more
• Required by most programming languages
• If garbage collection is used, additional problems
  occur
   – The initial setting of the indicators of all cells in the heap is
     difficult
   – The marking process in nontrivial
   – Maintaining the list of available space is another source of
     overhead
6.10 Type Checking
Type Checking




 Activity of ensuring that the                             Type Error
operands of an operator are of
       compatible types


                                                 Application of an operator to an
                                                  operand of an inappropriate
                                                               type
Types of Type
                                    Checking



Static type checking                          Dynamic type checking

•Perform type checking                        • Perform type checking during
 before runtime                                 runtime
•For static type binding                      • For dynamic type binding
 languages                                      languages

Exp: Earlier assembler, FORTRAN               • Exp: JavaScript, PHP


Advantages:                                       Advantage:
-earlier detection of                             - easier to handle situations that
programming mistakes                                require self-modifying code
- increased runtime efficiency

Disadvantage:                                     Disadvantage:
-Longer compilation time                          -longer runtime
6.11 Strong Typing
Strong
                                            Type


                          Programming language is strongly
                            typed if type errors are always
                                       detected.


Advantage:
                                                       Disadvantage:
-Ability to detect all misuses of
                                                       - Weakened by coercion
variables that result in type errors
-Also allows the detection at run time


  Language                     Range                           Comments
  Fortran 95                   Not strongly typed              Because the use of Equivalence
                                                               between variables of different types
  Ada                          Nearly strong typed             Allows the breach of type-checking
                                                               rules using function
                                                               Unchecked_Conversion
  C, C++                       Not strongly typed              Both include union types, which are
                                                               not typed checked
  Java, C#                     Nearly strongly typed           Types can be explicitly cast, which
                                                               could result in a type error
6.12 Type Equivalence
Type                                        Type
              Compatibility                               Equivalence




                                            An operand of one type in an expression
Types of operand that are acceptable for
                                             is substituted for one of the other type
each of the operators and thereby specify
                                            without coercion – compatibility without
 the possible type errors of the language
                                                             coercion
Types of Type
                                             Equivalence
 Name type equivalence                                      Structure type equivalence

• Two name have equivalence                                 • Equivalence if their types have
  type if they are defined under                              identical structure.
  the same declaration or
  declaration that use the same
  type name.
                                                            Advantage:
                                                            - more flexible
Advantages:
- Easy to implement
- More restrictive
                                                     Disadvantage:
Disadvantage:                                        - More difficult to implement
- Subrange of the integers would not be              - Entire structure of the two types
  equivalent to an integer type variable.              must be compared



   type Indextype is 1..100;
                                                            type Celsius = Float;
   count : Integer;
                                                                 Fahrenheit = Float;
   index : Indextype;
Derived
                              Type



•   New type that is based on previously defined type
•   Not equivalent although it may have identical structure
•   Inherit all the properties of their parent types
•   Can include range constraints on the parent type, while still
    inheriting all the parent’s properties




              type Celsius is new Float;
              type Fahrenheit is new Float;
Subtype



      Type equivalent to its
          parent type




subtype Small_type is Integer
range 0.99;
The type Small_type is
equivalent to the type Integer
6.13 Theory & Data Types
Theory




              •Type lambda calculus
              •Combinators
              •The Methatheory of Bounded Quantification
              •Existential Types
              •Higher-Order Polymorphism




 Practical
                                            Abstract
• Concerned with data
                                           • Focuses on type lambda
 types in commercial
                                             calculus
 programming languages
Data Type




                                                         Type System
Set of values and a collection of
  operations on those values.



                                                Set of types and the values that
                                                 govern their use in programs
Model Of Type
                                 System


 Formal model                                 Alternative model

Set of types and a                             • Uses a type map and a
collection of functions that                     collection of functions
define the type rules of the
language, which are used
to determine the type of
any expression


                                   Typed
                                 Language

 Static typed language                         Dynamic typed language

• Type map need only be                        • Type map must be
  maintained during                              maintained during
  compilation time                               execution
Chapter 6 data types

More Related Content

What's hot

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword pptVinod Kumar
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloadinggarishma bhatia
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computingjayavignesh86
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryKumar Gaurav
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 

What's hot (20)

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Java keywords
Java keywordsJava keywords
Java keywords
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
OOP java
OOP javaOOP java
OOP java
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Java threads
Java threadsJava threads
Java threads
 
Daa unit 5
Daa unit 5Daa unit 5
Daa unit 5
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Array in c++
Array in c++Array in c++
Array in c++
 

Viewers also liked

When athletes retire problems leaving the sports arena
When athletes retire problems leaving the sports arenaWhen athletes retire problems leaving the sports arena
When athletes retire problems leaving the sports arenaYasir Hameed
 
Nervous system
Nervous systemNervous system
Nervous systembsullivan4
 
bureau rowin petersma 2015
bureau rowin petersma 2015bureau rowin petersma 2015
bureau rowin petersma 2015Rowin Petersma
 
Google refine tutotial
Google refine tutotialGoogle refine tutotial
Google refine tutotialVijaya Prabhu
 
Understanding the sociocultural context through partnership with communities
Understanding the sociocultural context through partnership with communitiesUnderstanding the sociocultural context through partnership with communities
Understanding the sociocultural context through partnership with communitiesruthcwhite
 
Презентация Wikimart
Презентация WikimartПрезентация Wikimart
Презентация WikimartBEST_Moscow
 
Workshops of the Congress of the Royal College of Psychiatrists 24-27 June 2...
Workshops of the Congress of the Royal College of Psychiatrists  24-27 June 2...Workshops of the Congress of the Royal College of Psychiatrists  24-27 June 2...
Workshops of the Congress of the Royal College of Psychiatrists 24-27 June 2...Yasir Hameed
 
YouTube進階應用2
YouTube進階應用2YouTube進階應用2
YouTube進階應用2欣彥 郭
 
Trainees workshops
Trainees workshopsTrainees workshops
Trainees workshopsYasir Hameed
 
Google refine from a business perspective
Google refine   from a business perspectiveGoogle refine   from a business perspective
Google refine from a business perspectiveVijaya Prabhu
 
The Reproductive System
The Reproductive SystemThe Reproductive System
The Reproductive Systembsullivan4
 
Are negative findings all down to confounding factors?
Are negative findings all down to confounding factors?Are negative findings all down to confounding factors?
Are negative findings all down to confounding factors?Yasir Hameed
 
Presentatie Ruilklassen Weerijs
Presentatie Ruilklassen WeerijsPresentatie Ruilklassen Weerijs
Presentatie Ruilklassen Weerijsthijsseng
 
Ruth White Cv11.11.11
Ruth White Cv11.11.11Ruth White Cv11.11.11
Ruth White Cv11.11.11ruthcwhite
 
Google refine from a business perspective
Google refine   from a business perspectiveGoogle refine   from a business perspective
Google refine from a business perspectiveVijaya Prabhu
 

Viewers also liked (20)

When athletes retire problems leaving the sports arena
When athletes retire problems leaving the sports arenaWhen athletes retire problems leaving the sports arena
When athletes retire problems leaving the sports arena
 
Nervous system
Nervous systemNervous system
Nervous system
 
bureau rowin petersma 2015
bureau rowin petersma 2015bureau rowin petersma 2015
bureau rowin petersma 2015
 
Google refine tutotial
Google refine tutotialGoogle refine tutotial
Google refine tutotial
 
Understanding the sociocultural context through partnership with communities
Understanding the sociocultural context through partnership with communitiesUnderstanding the sociocultural context through partnership with communities
Understanding the sociocultural context through partnership with communities
 
Teste
TesteTeste
Teste
 
Презентация Wikimart
Презентация WikimartПрезентация Wikimart
Презентация Wikimart
 
Workshops of the Congress of the Royal College of Psychiatrists 24-27 June 2...
Workshops of the Congress of the Royal College of Psychiatrists  24-27 June 2...Workshops of the Congress of the Royal College of Psychiatrists  24-27 June 2...
Workshops of the Congress of the Royal College of Psychiatrists 24-27 June 2...
 
YouTube進階應用2
YouTube進階應用2YouTube進階應用2
YouTube進階應用2
 
Trainees workshops
Trainees workshopsTrainees workshops
Trainees workshops
 
Bose corporation
Bose corporationBose corporation
Bose corporation
 
Google refine from a business perspective
Google refine   from a business perspectiveGoogle refine   from a business perspective
Google refine from a business perspective
 
Servicios de-streaming
Servicios de-streamingServicios de-streaming
Servicios de-streaming
 
The Reproductive System
The Reproductive SystemThe Reproductive System
The Reproductive System
 
Are negative findings all down to confounding factors?
Are negative findings all down to confounding factors?Are negative findings all down to confounding factors?
Are negative findings all down to confounding factors?
 
Presentatie Ruilklassen Weerijs
Presentatie Ruilklassen WeerijsPresentatie Ruilklassen Weerijs
Presentatie Ruilklassen Weerijs
 
Ruth White Cv11.11.11
Ruth White Cv11.11.11Ruth White Cv11.11.11
Ruth White Cv11.11.11
 
Ptc
PtcPtc
Ptc
 
Google refine from a business perspective
Google refine   from a business perspectiveGoogle refine   from a business perspective
Google refine from a business perspective
 
Angles complementaris
Angles complementarisAngles complementaris
Angles complementaris
 

Similar to Chapter 6 data types

Chapter 2 basic element of programming
Chapter 2 basic element of programming Chapter 2 basic element of programming
Chapter 2 basic element of programming Zul Aiman
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming NeedsRaja Sekhar
 
Xbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for JavaXbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for Javameysholdt
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in javaGaruda Trainings
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
object oriented programming in java lecture
object oriented programming in java lectureobject oriented programming in java lecture
object oriented programming in java lectureMSohaib24
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxPRASENJITMORE2
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++NIDA HUSSAIN
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicGieno Miao
 

Similar to Chapter 6 data types (20)

Plc (1)
Plc (1)Plc (1)
Plc (1)
 
Plc (1)
Plc (1)Plc (1)
Plc (1)
 
Chapter 2 basic element of programming
Chapter 2 basic element of programming Chapter 2 basic element of programming
Chapter 2 basic element of programming
 
Jvm internals
Jvm internalsJvm internals
Jvm internals
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Cpprm
CpprmCpprm
Cpprm
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Xbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for JavaXbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for Java
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Pooja
PoojaPooja
Pooja
 
Pooja
PoojaPooja
Pooja
 
object oriented programming in java lecture
object oriented programming in java lectureobject oriented programming in java lecture
object oriented programming in java lecture
 
Datatype
DatatypeDatatype
Datatype
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Theory1&2
Theory1&2Theory1&2
Theory1&2
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamic
 

Recently uploaded

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Chapter 6 data types

  • 1. Data Types (Chapter 6) Name: ID: AHMAD ARAFAT BIN MOHD ALI 1091105499 NUR FAIRUZ BINTI MUHAMED ASRI 1091104133 SYUHAIDA AHMAD ARIFFIN 1101108762 SURAYA NURAIN BINTI KALID 1101109398
  • 2. • What is data type? int x = 5;
  • 3.
  • 4. Boolean Character - Charter types are stored as numeric codings They are used to represent switched and flags in programs. - (ASCII / Unicode). Complex Single Precision Numeric Floating Point Types Double Precision Decimal Floating Point: Integer 1) Single Precision: Primitive Data Types Boolean Integer Decimal: Complex Type: Bytes Example: (in C#) decimal myMoney = 300.5m; Java Example (in Phyton): 2) Double Precision: Long (7+3j) ASCII Advantage: Greater precision and a smaller range compared to Floating Point Character Short Programming Languages that support Complex Type: Unicode Fortran, Phyton
  • 5.
  • 6. Limited Dynamic String Strings Dynamic Length Length Static Length String: Design Issues 1) Static or dynamic? --The length canvarious lengthset whenmaximum. is created Special Type of character String strings can store any number of chars between2) -Allowsvariablesbe static and with no the string zero and the maximum -Requires ‘0’ is used to indicate the end of string’s characters (used primitive types? array or by C) -Delimiter the overhead of dynamic storage allocation and deallocation but provides flexibility Example Fotran-90: Character (LEN=15) name; Comparison Assignment Example: JavaScript and Perl Operations Concatenation on String Character String Substring Types Copy Length Example: Example: Assume s=“good”, t=“bye” Assume s=“good”, t=“bye” Assume s=“good”, t=“bye” Static Length String strcpy(x,s); = //return false String length if (s.equals(t)) “goo”; strlen(s)=3;,‘hello’- Strcat(s,t)=goodbye Char x *+ = Subs(s1,0,2) (Fixed Length) Options Limited Dyna mic x=good Length String Dynamic Length String
  • 7.
  • 8. User-Defined Ordinal Types Enumeration Subrange Types Types 2) Enumeration Types - provides a of defining and grouping collections of named 1) Subrange Types - provides a way way of defining and grouping collections of named constant. constant. Example In Ada: C#: type Days is (Mon, Tue, Wed Thu, Fri, Sat, Sun); enum days {Mon, Tue,Wed, Thu, Fri, Sat, Sun}; subtype Weekdays is Days range Mon..Fri; subtype Index Advantage: is Integer range 1..100; a) Readibility – Named values are easily recognized Advantages: b) Realibility – No arithmetic operations are legal on enumeration type a) Enhance Readibility – variable of subtype can store only certain range. b) Realibility (use integer values to represent enumeration to assign Example in C– because a compiler can detect error if we try type): value to a specified subrange value. int red = 0, blue = 1
  • 9. Categories Of Array Categories of Range of Storage Bindings Advantages Example Array subscripts 1. Static Array Statically bound Static (done Execution Fortran-77, C, C++ before runtime) efficiency 2. Fixed Stack Statically bound Done during Storage space C , C++ Dynamic Array execution can be reused 3. Stack Dynamic Dynamic Dynamic Flexibility Ada Array 4. Fixed Heap Fixed after Fixed after Flexibility Fortran 95, C, Dynamic Array storage is storage is C++, Java, C# allocated allocated -done when -allocated from user program the heap requests during execution 5. Heap Dynamic Dynamic Dynamic Flexibility C#, Java, Array JavaScript, Python, Ruby
  • 10. Array Initialization Programming Language How it is initialize? 1. Fortran 95 Integer, Dimension (3) :: List = (/0, 5, 5 /) 2. C and C++ int list [ ] = {4, 5, 7, 83}; int list [3] = {3, 5, 7}; char name * + = “freddie”; 3. Java String[ + names = *“Bob”, “Jake”+; Array Operation Programming Language Example Operation Fortran 95 ( + ) operator Give result sum of element pairs of the two arrays.
  • 11. Rectangular Array Jagged Array Language supported: Language supported:  Fortran  Java  Ada  C  C#  C++  C#
  • 12. [0] [1] [2] [0] 2 6 10 [1] 3 5 8 Implementation Of Array Types [2] 12 1 7 Row Major Order Column Major Order Int num[3][3]; Int num[3][3]; [0] [1] [2] [1] [2] [3] [0] 2 6 10 [1] 2 6 10 [1] 3 5 8 [2] 3 5 8 [2] 12 1 7 [3] 12 1 7 2 6 10 3 5 8 12 1 7 2 3 12 6 5 1 10 8 7 Language : C, Pascal, Java Language : Fortran
  • 13. Record type What is record? Record is an aggregate of data elements in which the individual elements are identified by names and accessed through offset from the beginning of the structure.
  • 14. Differences between Record and Array Record Array Fields are referenced by using Fields are referenced by their names indices Use when the collection of Use when all the data data objects is heterogeneous elements have same type and and fields are not processed in are processed in same way. same way. Fields of records are not Processing of array elements is processed in any particular usually done by in a sequential sequential order. order
  • 15. Operations on Records Programming Operation Languages Ada 1. Allow comparison  = (equality)  /= (inequality) 2. Initialize with aggregate literals. COBOL 1. Provide MOVE CORRESPONDING Example: MOVE CORRESPONDING INPUT_RECORD TO OUTPUT_RECORD. 01 INPUT_RECORD. 02 NAME. 05 LAST PICTURE IS X (20). 05 MIDDLE PICTURE IS X (15). 05 FIRST PICTURE IS X (20) . 02 EMPLOYEE_NUMBER PICTURE IS 9 (10). 02 HOURS_WORKED PICTURE IS 99. 01 OUTPUT_RECORD. 02 NAME. 05 LAST PICTURE IS X (20). 05 MIDDLE PICTURE IS X (15). 05 FIRST PICTURE IS X (20) . 02 EMPLOYEE_NUMBER PICTURE IS 9 (10). 02 GROSS_PAY PICTURE IS 999V999. 02 NET_PAY PICTURE IS 999V999.
  • 16. Language Name Type Equivalent Structure Type Equivalent Ada Works well More rigid C Works well Works well C++ Works well Works well Fortran Cannot use Works well COBOL Cannot use Works well
  • 17. 6.8 Union Type Introduction • A union is a type whose variables are allowed to store different type values at different times during execution. • Example: union foo { union foo x; int a; x.a = 3; // OK char b; x.b = 'c'; } foo; // NO! this affects the value of x.a! //can’t use both a and b at the same time Prints out 99,99 struct bar { struct bar y; int a; y.a = 3; // OK char b; y.b = 'c'; // OK } bar; //can use a and b simultaneously Prints out 387427, 99
  • 18. 6.8.2 Discriminated versus free unions Type of Unions Discriminated Free Unions Unions It has a type checking support for unions Fortran, C, and C++ provide require that each union include a type union constructs in which indicator. The first language to provide discriminated there is no language support union was ALGOL 68 which is later supported for type checking therefore it by ADA. is unsafe to use in these languages. Unconstrained Constrained Variant Variable Variant Variable
  • 19. 6.8.3 Ada union type Ada union type Constrained variant Unconstrained variant variable records Allow the values of their variants to change types Allows the user to specify during execution. The type can only be changed variables of a variant only by assigning the entire record, including the record type that will store discriminant. only one of the possible This disallows inconsisient records because if the type values in the variant. newly assigned record is a constant data In this way, the user can aggregate, the value of the tag and the type of tell the system when the variant can be statically checked for consistency. type checking can be static, because we know If the assigned value is a variable, its consistency that type checking must be was guaranteed when it was assigned, so the new dynamic. value of the variable now being assigned is sure to be consistent.
  • 20. How does union implemented in At compile time, programming the complete languages? description of each variant must be Use the same address stored by creating a for every variant. case table. In Ada language, the Sufficient storage for exact amount of the largest variant is storage can be used allocated. because there is no variation.
  • 21. The descriptor for this type could have the form shown in the figure below:
  • 22. 6.9 Pointer and reference type Introduction • A pointer type variable has a range of values that consists of memory addresses and a special value, nil • Provide the power of indirect addressing • Provide a way to manage dynamic memory • A pointer can be used to access a location in the area where storage is dynamically created (usually called a heap)
  • 23. 6.9.2 Pointer operations • Language that provide pointer has two fundamental operations: assignment and dereferencing • Assignment is used to set a pointer variable’s value to some useful address • Dereferencing yields the value stored at the location represented by the pointer’s value – Dereferencing can be explicit or implicit – C++ uses an explicit operation via * (asterisk) j = *ptr sets j to the value located at ptr
  • 24. Problems with pointer Dangling lost heap- pointers dynamic (dangerous) variable A pointer points An allocated heap-dynamic to a heap- variable that is no longer dynamic variable accessible to the user program (often called that has been garbage) deallocated. 1. Pointer p1 is set to point to a newly created heap-dynamic variable 2. Pointer p1 is later set to point to another newly created heap-dynamic variable 3. The first heap –dynamic variable is now inaccessible (memory leakage).
  • 25. Pointers Ada C++ • It is called access types • Extremely flexible but must be used with care • Some dangling • Pointers can point at any variable regardless of pointers are when it was allocated disallowed because • Used for dynamic storage management and dynamic objects can addressing be automatically de- • Pointer arithmetic is possible allocated at the end of • Explicit dereferencing and address-of operators pointer's type scope • Domain type need not be fixed (void *) • The lost heap- • void * can point to any type and can be type dynamic variable checked (cannot be de-referenced) problem is not eliminated by Ada.
  • 26. 6.9.6 Reference types • C++ includes a special kind of pointer type called a reference type that is used primarily for formal parameters – Advantages of both pass-by-reference and pass-by-value • Java extends C++’s reference variables and allows them to replace pointers entirely – References refer to call instances • C# includes both the references of Java and the pointers of C++
  • 27. 6.9.7 Evaluation of pointers • Dangling pointers and dangling objects are the same problems as is heap management • Pointers are like goto's--they widen the range of cells that can be accessed by a variable • Pointers or references are necessary for dynamic data structures--so we can't design a language without them.
  • 28. Implementation of pointers and reference type Representation of Solutions to dangling pointers and Heap management pointers referencces Tombstone: extra heap cell that is a pointer A very complex run-time • Large to the heap-dynamic variable process computers use single The actual pointer variable points only Single-size cells vs. variable- at tombstones size cells values When heap-dynamic variable de- • Intel Two approaches to reclaim allocated, tombstone remains but set microproce garbage to nil ssors use Reference counters segment Costly in time and space (eager approach): and offset Locks-and-keys: Pointer values are represented as (key, address) pairs reclamation is gradual Heap-dynamic variables are Garbage collection (lazy represented as variable plus cell for approach): reclamation integer lock value occurs when the list of When heap-dynamic variable variable space becomes allocated, lock value is created and empty placed in lock cell and key cell of pointer
  • 29. Reference counter • Reference counters: maintain a counter in every cell that store the number of pointers currently pointing at the cell – Disadvantages: space required, execution time required, complications for cells connected circularly – Advantage: it is intrinsically incremental its actions are interleaved with those of the applicasion so it never causes significant delays in the execution of the application.
  • 30. Garbage collection • The run-time system allocates storage cells as requested and disconnects pointers from cells as necessary; garbage collection then begins – Every heap cell has an extra bit used by collection algorithm – All cells initially set to garbage – All pointers traced into heap, and reachable cells marked as not garbage – All garbage cells returned to list of available cells – Disadvantages: when you need it most, it works worst (takes most time when program needs most of cells in heap)
  • 32. Variable sized cells • All the difficulties of single-size cells plus more • Required by most programming languages • If garbage collection is used, additional problems occur – The initial setting of the indicators of all cells in the heap is difficult – The marking process in nontrivial – Maintaining the list of available space is another source of overhead
  • 34. Type Checking Activity of ensuring that the Type Error operands of an operator are of compatible types Application of an operator to an operand of an inappropriate type
  • 35. Types of Type Checking Static type checking  Dynamic type checking •Perform type checking • Perform type checking during before runtime runtime •For static type binding • For dynamic type binding languages languages Exp: Earlier assembler, FORTRAN • Exp: JavaScript, PHP Advantages: Advantage: -earlier detection of - easier to handle situations that programming mistakes require self-modifying code - increased runtime efficiency Disadvantage: Disadvantage: -Longer compilation time -longer runtime
  • 37. Strong Type Programming language is strongly typed if type errors are always detected. Advantage: Disadvantage: -Ability to detect all misuses of - Weakened by coercion variables that result in type errors -Also allows the detection at run time Language Range Comments Fortran 95 Not strongly typed Because the use of Equivalence between variables of different types Ada Nearly strong typed Allows the breach of type-checking rules using function Unchecked_Conversion C, C++ Not strongly typed Both include union types, which are not typed checked Java, C# Nearly strongly typed Types can be explicitly cast, which could result in a type error
  • 39. Type Type Compatibility Equivalence An operand of one type in an expression Types of operand that are acceptable for is substituted for one of the other type each of the operators and thereby specify without coercion – compatibility without the possible type errors of the language coercion
  • 40. Types of Type Equivalence  Name type equivalence  Structure type equivalence • Two name have equivalence • Equivalence if their types have type if they are defined under identical structure. the same declaration or declaration that use the same type name. Advantage: - more flexible Advantages: - Easy to implement - More restrictive Disadvantage: Disadvantage: - More difficult to implement - Subrange of the integers would not be - Entire structure of the two types equivalent to an integer type variable. must be compared type Indextype is 1..100; type Celsius = Float; count : Integer; Fahrenheit = Float; index : Indextype;
  • 41. Derived Type • New type that is based on previously defined type • Not equivalent although it may have identical structure • Inherit all the properties of their parent types • Can include range constraints on the parent type, while still inheriting all the parent’s properties type Celsius is new Float; type Fahrenheit is new Float;
  • 42. Subtype Type equivalent to its parent type subtype Small_type is Integer range 0.99; The type Small_type is equivalent to the type Integer
  • 43. 6.13 Theory & Data Types
  • 44. Theory •Type lambda calculus •Combinators •The Methatheory of Bounded Quantification •Existential Types •Higher-Order Polymorphism  Practical  Abstract • Concerned with data • Focuses on type lambda types in commercial calculus programming languages
  • 45. Data Type Type System Set of values and a collection of operations on those values. Set of types and the values that govern their use in programs
  • 46. Model Of Type System  Formal model Alternative model Set of types and a • Uses a type map and a collection of functions that collection of functions define the type rules of the language, which are used to determine the type of any expression Typed Language  Static typed language  Dynamic typed language • Type map need only be • Type map must be maintained during maintained during compilation time execution