You are on page 1of 3

PRIMITIVE DATA TYPE Michael and Efren

Data Objects -container or they are memory spaces where data values may be stored and later retrieved. Two types Programmer-defined- is one explicitly created and manipulated by the programmer through declarations and statements in the program. Ex: constants and variables declared in the program System-defined-is one set up by the virtual computer for housekeeping during program execution and one that is not directly accessible to the programmer. Ex: data objects maintained by the virtual computer Attributes: Value type type of values that the data object may contain. Size the amount of storage needed to store the values. Lifetime how long do the data object exists. Data Values and Values Types A value is 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 is just a set of values. Primitive type- is one whose value is atomic and therefore cannot be decomposed. Composite type-is a type whose values are composed or structured from simpler values Recursive type-is a special case of composite type where the values are of the same type. Data Type is a class of data objects together with the set of operations for creating and manipulating them.

PRIMITIVE DATA TYPES

Data types that are not required in terms of other types

NUMERIC TYPES INTEGER The most common primitive numeric data type is integer. For example, Ada allows these: short integer, integer and long integer. An integer is represented by a string of bits, with the leftmost representing the sign bit. FLOATING-POINT On most computers, floating-point numbers are stored in binary Floating-point values are represented as fractions and exponents Most languages use float and double as floating-point types The float is stored in 4 bytes of memory The double has twice as big of storage

DECIMAL store a fixed number of decimal digits, with the decimal point at a fixed position in the value

ENUMERATION TYPES An enumeration type in one in which all of the possible values, which become symbolic constants, are enumerated in the definition. Ex. in Ada: type DAYS is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); Enumeration types have advantages to readability and reliability. SUBRANGE TYPES A sub range type is a contiguous subsequence of an ordinal type. Ex, 12 ... 14 is a sub range of integer type. BOOLEAN TYPES These are the simplest of all types and were introduced in ALGOL 60 The range of values has only two elements - TRUE or FALSE Boolean types are often used to represent switches or flags in programs George Boole - an Irish mathematicians who invented boolean algebra CHARACTER TYPES These are stored as numeric coding The most commonly used coding is ASCII A new 16-bit character set named Unicode had been developed as an alternative Java is the first to use Unicode

DECLARATIONS
-is the part of a program where the programmer communicates to the language translator. Two types: Implicit- is found in languages where data objects are created whenever they are about to be used. Explicit-serves several purposes both for the programmer and the language translator.

Purposes: Choice of Storage Management Storage representation Generic operations Type Checking Why Variables are declared? So that operations for that variable may be known To support overloaded operations To allocate just enough memory for that variable

BINDING
-is an association such as between an attribute and an entity or between an operation and a symbol

Classes: Execution time- performed during program execution. Two main categories: On entry to a subprogram or block At arbitrary points during execution Translation Time Classes: Binding chosen by the programmer Binding chosen by the translator Binding chosen by the loader Language Definition Time set by the designer of the language Language Implementation Time brought about by the differences in hardware where programming languages are implemented.

TYPE CHECKING
-is the processes of identifying errors in a program based on explicitly or implicitly stated type information -A language is dynamically typed if the type of a variable is interpreted at runtime. This means that you as a programmer can write a little quicker because you do not have to specify type every time. Example: Perl -A language is statically typed if the type of a variable is known at compile time. This in practice means that you as the programmer must specify what type each variable is. Example: Java, C, C++

TYPE CONVERSION AND COERCION


Type Conversion must be done implicitly(coercion) or explicitly, Coercion is a way by which a data object of certain type is changed to the correct type. Example: x : n*1.2;

Explicitly type conversion is done using built-in functions provided in the language for the purpose of changing types. For example in Pascal : ROUND and TRUNC

You might also like