SlideShare a Scribd company logo
1 of 4
Primitive Data Types

Data Objects
     Memory spaces where data values may be stored and later retrieved.

Two types of data objects:
  • Programmer-defined data object
           Explicitly created and manipulated by the programmer through declarations
           and statements in the program.
  • System-defined data object
           Set up by the virtual computer for housekeeping during program execution
           and one that is not accessible to the programmer.

  • A data object has attributes. One important attribute is the value type.
  • Another attribute is the size.
  • Another important consideration in data objects is their lifetime, that is, how long
    does the data object exists. This is usually related to when the data object is
    created ordestroyed.

                              Data Values and Values Types

Value
        Anything that may be evaluated, stored, passed as argument to a procedure,
        returned by a function; or given as a component of a data structure.

Value Type
     A set of values. In programming language, the types of values are either of
     primitive type or composite type. Other languages have recursive types.

Types of Values:
  • Primitive Type
           One whose value is atomic and therefore cannot be decomposed.
  • Composite Type
           A type whose values are composed or structured from simpler values.
  • Recursive Type
           A special case of composite type where the values are of the same type.
Data Types

Data Type
     A classification of data, which can store a specific type of information. Data types
     are primarily used in computer programming, in which variables are created to
     store data.

Primitive Data Type
      Predefined types of data, which are supported by the programming language. For
      example, integer, character, and string are all primitive data types. Programmers
      can use these data types when creating variables in their programs.

Numeric Data Type
    All programming languages have some form of numeric data types. The most
    common are the integer and real number types.
    An example is C, where the type int (integer) has an added attribute for the
    number of bytes used to represent the integer. This results in two types of integer
    types: long and short.
          Example: short i;
                long k;

Subrange Type
     Introduced to save on storage and for better type checking.

Enumeration Type
    A special data type that enables for a variable to be a set of predefined constants.
    The variable must be equal to one of the values that have been predefined for it.
    Common examples include compass directions (values of NORTH, SOUTH, EAST,
    and WEST) and the days of the week.

Boolean or Truth Value Type
     A data type having one of the two possible values, true or false.

Character Type
     Found in almost programming language. The natural extension is the character-
     string data type.

            Example:char letter;
                letter = 'A';
Declarations
     A declaration statement is used to declare a variable by specifying its data type
     and name.
           Example:int number = 10;
                 booleanisFinished = false;
                 String welcomeMessage = "Hello!";

Two types of declarations:
  1. Explicit-done by the programmer.
  2. Implicit - found in languages where data objects are created whenever they are
     about to be used.

     An explicit declaration serves several purposes both for the programmer and the
     language translator. Some of these purposes are:
     1. Choice of storage representation
     With this information, the translator can make arrangement to allocate the right
     amount of storage for a variable.
     2. Storage management
     This information is very useful for managing the storage during run time.
     3. Generic operations
     With declaration of variables, overloaded operations can easily be supported and
     efficiently implemented.
     4. Type Checking
     The main purpose of a declaration in most languages is to facilitate static type
     checking.

Binding
      Describes how a variable is created and used (or "bound") by and within the given
      program and, possibly, by other programs, as well.

Classes of Binding:
1. Binding performed at execution time
2. Binding performed at translation time
3. Binding performed at language definition time as another class
4. Binding that occurs at implementation time

Type Checking
     Done to ensure that an operation is provided with the correct types.Consider for
example the operation, a := b + c;

Two types of Type Checking:
       1. Static – done during compilation
       2. Dynamic – done during execution

Type Equivalence
     When two data objects are involved in one operation, the issue of type
     equivalence arises.

                            Type Conversion and Coercion

Type Conversion
     An operation that converts a data object of one type and produces the
     corresponding data object in another type.
     Example:




Coercion
     Process by which a compiler automatically converts a value of one type into a
     value of another type when that second type is required by the surrounding
     context.
     Example:




Initialization
       When an elementary data type is declared, a memory location is created for it. To
       give the data type an initial value, an assignment statement may be explicitly
       written at the beginning of the program.
       Example: inti = 1;

More Related Content

What's hot

Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingVIKASH MAINANWAL
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHoang Nguyen
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Unit 5-hive data types – primitive and complex data
Unit 5-hive data types – primitive and complex dataUnit 5-hive data types – primitive and complex data
Unit 5-hive data types – primitive and complex datavishal choudhary
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4sumitbardhan
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environmentsJ'tong Atong
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data typesjigeno
 
Arrays 2 Dimensional Unit 2 Part 1.pdf
Arrays 2 Dimensional Unit 2 Part 1.pdfArrays 2 Dimensional Unit 2 Part 1.pdf
Arrays 2 Dimensional Unit 2 Part 1.pdfArpana Awasthi
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of funcSanjayKumarMahto1
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
File Handling in C Part I
File Handling in C Part IFile Handling in C Part I
File Handling in C Part IArpana Awasthi
 

What's hot (20)

Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
10. sub program
10. sub program10. sub program
10. sub program
 
Unit 5-hive data types – primitive and complex data
Unit 5-hive data types – primitive and complex dataUnit 5-hive data types – primitive and complex data
Unit 5-hive data types – primitive and complex data
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
 
C- language Lecture 4
C- language Lecture 4C- language Lecture 4
C- language Lecture 4
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
Arrays 2 Dimensional Unit 2 Part 1.pdf
Arrays 2 Dimensional Unit 2 Part 1.pdfArrays 2 Dimensional Unit 2 Part 1.pdf
Arrays 2 Dimensional Unit 2 Part 1.pdf
 
Subprogram
SubprogramSubprogram
Subprogram
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 
Csci360 08-subprograms
Csci360 08-subprogramsCsci360 08-subprograms
Csci360 08-subprograms
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
Data structures
Data structuresData structures
Data structures
 
File Handling in C Part I
File Handling in C Part IFile Handling in C Part I
File Handling in C Part I
 

Similar to Primitive data types (20)

Datatypes in C++.pptx
Datatypes in C++.pptxDatatypes in C++.pptx
Datatypes in C++.pptx
 
Language design and translation issues
Language design and translation issuesLanguage design and translation issues
Language design and translation issues
 
Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)
 
Type Checking
Type CheckingType Checking
Type Checking
 
Type system
Type systemType system
Type system
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
 
java handout.doc
java handout.docjava handout.doc
java handout.doc
 
Data types
Data typesData types
Data types
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Introduction to ‘C’ Language
Introduction to ‘C’ LanguageIntroduction to ‘C’ Language
Introduction to ‘C’ Language
 
C programming
C programmingC programming
C programming
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
C# Basics
C# BasicsC# Basics
C# Basics
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
 
Data Types in C language
Data Types in C languageData Types in C language
Data Types in C language
 
Data Types
Data TypesData Types
Data Types
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Pc module1
Pc module1Pc module1
Pc module1
 

Primitive data types

  • 1. Primitive Data Types Data Objects Memory spaces where data values may be stored and later retrieved. Two types of data objects: • Programmer-defined data object Explicitly created and manipulated by the programmer through declarations and statements in the program. • System-defined data object Set up by the virtual computer for housekeeping during program execution and one that is not accessible to the programmer. • A data object has attributes. One important attribute is the value type. • Another attribute is the size. • Another important consideration in data objects is their lifetime, that is, how long does the data object exists. This is usually related to when the data object is created ordestroyed. Data Values and Values Types Value Anything that may be evaluated, stored, passed as argument to a procedure, returned by a function; or given as a component of a data structure. Value Type A set of values. In programming language, the types of values are either of primitive type or composite type. Other languages have recursive types. Types of Values: • Primitive Type One whose value is atomic and therefore cannot be decomposed. • Composite Type A type whose values are composed or structured from simpler values. • Recursive Type A special case of composite type where the values are of the same type.
  • 2. Data Types Data Type A classification of data, which can store a specific type of information. Data types are primarily used in computer programming, in which variables are created to store data. Primitive Data Type Predefined types of data, which are supported by the programming language. For example, integer, character, and string are all primitive data types. Programmers can use these data types when creating variables in their programs. Numeric Data Type All programming languages have some form of numeric data types. The most common are the integer and real number types. An example is C, where the type int (integer) has an added attribute for the number of bytes used to represent the integer. This results in two types of integer types: long and short. Example: short i; long k; Subrange Type Introduced to save on storage and for better type checking. Enumeration Type A special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week. Boolean or Truth Value Type A data type having one of the two possible values, true or false. Character Type Found in almost programming language. The natural extension is the character- string data type. Example:char letter; letter = 'A';
  • 3. Declarations A declaration statement is used to declare a variable by specifying its data type and name. Example:int number = 10; booleanisFinished = false; String welcomeMessage = "Hello!"; Two types of declarations: 1. Explicit-done by the programmer. 2. Implicit - found in languages where data objects are created whenever they are about to be used. An explicit declaration serves several purposes both for the programmer and the language translator. Some of these purposes are: 1. Choice of storage representation With this information, the translator can make arrangement to allocate the right amount of storage for a variable. 2. Storage management This information is very useful for managing the storage during run time. 3. Generic operations With declaration of variables, overloaded operations can easily be supported and efficiently implemented. 4. Type Checking The main purpose of a declaration in most languages is to facilitate static type checking. Binding Describes how a variable is created and used (or "bound") by and within the given program and, possibly, by other programs, as well. Classes of Binding: 1. Binding performed at execution time 2. Binding performed at translation time 3. Binding performed at language definition time as another class 4. Binding that occurs at implementation time Type Checking Done to ensure that an operation is provided with the correct types.Consider for
  • 4. example the operation, a := b + c; Two types of Type Checking: 1. Static – done during compilation 2. Dynamic – done during execution Type Equivalence When two data objects are involved in one operation, the issue of type equivalence arises. Type Conversion and Coercion Type Conversion An operation that converts a data object of one type and produces the corresponding data object in another type. Example: Coercion Process by which a compiler automatically converts a value of one type into a value of another type when that second type is required by the surrounding context. Example: Initialization When an elementary data type is declared, a memory location is created for it. To give the data type an initial value, an assignment statement may be explicitly written at the beginning of the program. Example: inti = 1;