data types2

Upload: joshua-cabangcalan

Post on 06-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Data Types2

    1/17

  • 8/3/2019 Data Types2

    2/17

    y (or datatype) is a classification identifying one ofvarious types of data, such as floating-point, integer,

    or Boolean, that determines the possible values forthat type; the operations that can be done on values ofthat type; and the way values of that type can bestored.

  • 8/3/2019 Data Types2

    3/17

    y Almost all programming languages explicitly include the

    notion of data type, though different languages may use

    different terminology. Common data types may include:

    y Integers

    yBooleans

    yCharacters

    yFloating-point numbers

    yAlphanumeric strings

  • 8/3/2019 Data Types2

    4/17

    y Most programming languages also allow the

    programmer to define additional data types, usually bycombining multiple elements of other types anddefining the valid operations of the new data type.

    y Ex:

    a programmer might create a new data type named"complex number" that would include real and imaginaryparts.

  • 8/3/2019 Data Types2

    5/17

    y Adata type also represents a constraint placed upon

    the interpretation of data in a type system,describing representation, interpretation andstructure of values or objects stored in computermemory. The type system uses data type information

    to check correctness of computer programs thataccess or manipulate the data.

  • 8/3/2019 Data Types2

    6/17

    End

    y Algebraic data types

    y Function types

    y Machine data types

    y

    Object typesy Pointer and reference data types

    y Primitive data types

    NOTE:

    These are basic data types that are provided by the programming language with built-in

    support. These data types are native to the language.

  • 8/3/2019 Data Types2

    7/17

    Integers - is used to refer to a data type which represents some finite

    subset of the mathematical integers. These are also known as integral

    data types.

    Booleans or logical data type is a data type, having two values

    (usually denoted true and false), intended to represent the truth values

    of logic and Boolean algebra.

    Characters - is a unit of information that roughly corresponds to a

    grapheme, grapheme-like unit, or symbol, such as in an alphabet or

    syllabary in the written form of a natural language.

    Floating-pointnumbers - describes a system for representing real

    numbers which supports a wide range of values. Numbers are in general

    represented approximately to a fixed number of significant digits and

    scaled using an exponent.

  • 8/3/2019 Data Types2

    8/17

    y Alphanumeric strings - string is traditionally a sequence of

    characters, either as a literal constant or as some kind of variable. The

    latter may allow its elements to be mutated and/or the length

    changed, or it may be fixed (after creation).Astring is generally

    understood as a data type and is often implemented as a byte (or word)

    array that stores a sequence of elements, typically characters, using

    some character encoding.Astring may also denote more general array

    data types and/or other sequential data types and structures; terms

    such as byte string, or more general, string ofdatatype, or datatype-

    string, are sometimes used to denote strings in which the stored data

    does not (necessarily) represent text.

    BackBack

  • 8/3/2019 Data Types2

    9/17

    y (sometimes also called a variant type[1]) is a datatypeeach of whose values is data from other datatypeswrapped in one of the constructors of the datatype.Any wrapped datum is an argument to the constructor.

    In contrast to other datatypes, the constructor is notexecuted and the only way to operate on the data is tounwrap the constructor using pattern matching.

    y The most common algebraic data type is a list with two

    constructors: Nil or [] for an empty list, and Cons (anabbreviation ofconstruct), ::, or : for the combinationof a new element with a shorter list (for example Cons1[2, 3, 4] or 1:[2,3,4]).

  • 8/3/2019 Data Types2

    10/17

    y (also arrow type or exponential) is the type of avariable or parameter to which a function has or can beassigned or the result type of a higher-order functionreturning a function.

    y Afunction type depends on the type of the parametersand the result type of the function (it, or moreaccurately the unapplied type constructor , is ahigher-kinded type).

  • 8/3/2019 Data Types2

    11/17

    y

    All data in computers based on digital electronics isrepresented as bits (alternatives 0 and 1) on the lowestlevel. The smallest addressable unit of data is usually agroup of bits called a byte (usually an octet, which is 8bits). The unit processed by machine code instructions iscalled a word (as of2011, typically 32 or 64 bits).

    y Most instructions interpret the word as a binary number,such that a 32-bit word can represent unsigned integervalues from 0 to 232 1 or signed integer values from 231

    to 231 1. Because of two's complement, the machinelanguage and machine don't need to distinguish betweenthese unsigned and signed data types for the most part.

  • 8/3/2019 Data Types2

    12/17

    y is any entity that can be manipulated by thecommands of a programming language, such as avalue, variable, function, or data structure. (With the

    later introduction of object-oriented programming thesame word, "object", refers to a particular instance of aclass)

  • 8/3/2019 Data Types2

    13/17

    y is a value that enables a program to indirectly access aparticular data item, such as a variable or a record, inthe computer's memory or in some other storagedevice. The reference is said to refer to the data item,and accessing that data is called dereferencing thereference.

    y Areference is distinct from the data itself. Typically, areference is the physical address of where the data isstored in memory or in the storage device. For this

    reason, a reference is often called a pointer oraddress, and is said to point to the data. However areference may also be the offset (difference) betweenthe datum's address and some fixed "base" address, oran index into an array.

  • 8/3/2019 Data Types2

    14/17

    y Is either of the following:y a basic type is a data type provided by a programming

    language as a basic building block. Most languages allowmore complicated composite types to be recursively

    constructed starting from basic types.y a built-in type is a data type for which the programminglanguage provides built-in support.

    y In most programming languages, all basic data types

    are built-in. In addition, many languages also provide aset of composite data types. Opinions vary as towhether a built-in type that is not basic should beconsidered "primitive".

    BackBack

  • 8/3/2019 Data Types2

    15/17

  • 8/3/2019 Data Types2

    16/17

  • 8/3/2019 Data Types2

    17/17