Primitive data types
Upcoming SlideShare
Loading in...5

Primitive data types






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Primitive data types Primitive data types Document Transcript

  • Primitive Data TypesData 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 TypesValue 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 TypesData 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 time2. Binding performed at translation time3. Binding performed at language definition time as another class4. Binding that occurs at implementation timeType 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 executionType Equivalence When two data objects are involved in one operation, the issue of type equivalence arises. Type Conversion and CoercionType 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;