< Computer Programming

Computer Programming Types determine the kinds of values and how they can be used in the given programming environment. In most cases, a programming language defines a set of basic data types, e.g. for numbers, characters or strings. In higher languages, it is often possible to define new data types from the existing ones, for example, to represent a postal address (consisting of strings for street and city and integers for the postal code). When communicating data between different programs and computer systems it is important to either use types that both can recognize, or have a means of translating between them.

Type Definition

A complete definition of a data type consists of up to three things:

Physical representation 
how is the data stored
Operations 
what can you do with the data type (the meaning); what can you not do, such as divide by zero or string manipulation; and what happens if you "overflow" the buffers to do actions with results falling "outside" the space allotted
Automatic Functions 
what activities, outside program control, can change the data (hardware, user, system clock)

Primitive Types

There are a few basic data types seen in some programming languages:

Integer 
Unlimited in some languages, limited to 8-bit, 16-bit, 32-bit, 48-bit, 64-bit sizes in most languages (C, C++, C#, w:DDS, Java, w:RPG). In some languages (Ada, w:FORTH, PL/I) size can be freely defined.
Ratios 
e.g. 2/3, only a few languages have these.
Float 
Floating point, most languages offer single and double precision (C, C++, C#, DDS, Java, w:RPG). In some languages (Ada, PL/I) precision can be freely defined.
Decimal 
Base 10 (human) fixed point, often used for monetary values. Only a few languages (Ada, PL/I, w:SQL, COBOL, w:RPG, DDS) offer fixed point. Precision can usually be freely defined.
Hexadecimal 
Base 16 available on IBM Systems. Digits are zero through F. Most modern languages don't need a separate Hexadecimal type, they use integers and specialized I/O routines.
Packed Decimal 
Two digits can fit into same space as one character. Look at definition of character set for w:ASCII, w:EBCDIC, or similar conceptual system. Note letters and special characters are represented by two hexadecimal half bytes so with packed data, two digits can fit in same space as one letter. Usually one half byte is reserved for numeric sign (plus or minus).
Complex 
A complex value usually consisting of two Float values. Only a few languages (C99, Fortran) have these. In Object Oriented languages often implemented by a library (C++, Ada).
Character 
A character, usually of 8, 16 or 32 bit size. Some Characters sets, like UTF-8 are for a variable length.

Composite Types

Record  
An assorted combination of primitive types.
Variant  
Type is determined at runtime.
Object  
In Object Oriented languages.
Array  
See article Arrays.
String  
A sequence of characters. Often implemented as Array of Characters.

Type Attributes

Null Support 
In addition to data blank or zero, we can have null value, meaning we not yet know what belongs there.
DBCS Double Byte Character Set 
Some nations and cultures "alphabets" (such as Chinese, Japanese, Korean, Russian (Cyrillic)) can use graphical characters called ideograms to perform a role similar to the letters A to Z in western nations languages when constructing meanings, except each ideogram carries more meaning than each A to Z letter. Data types are available to store these graphical character sets, which contain more symbols than can be represented by the 256 combinations found in traditional western character sets, thus a double byte character set (DBCS) exists to account for every combination.
Some special fonts use a similar system.
Some bar coding uses similar concept.
Date Time and Duration  
These are special data types used to support date math, such as calculating number days between two dates.
Flags or Indicators  
They contain value like True / False or Yes / No. They are often used to recognize use of a keyboard function (which special keys got pressed); printer condition (ready for a new page); file access (we got the record we were looking for, we're now at end-of-file). These special conditions mean that special actions needed.
Variable Length 
Width of data is controlled by the content.

Language Specifics

See also

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.