Forgot your password?  

Not What You Meant?  There are 16 definitions for Type.

Types | Research & Encyclopedia Articles

Print-Friendly   Order the PDF version   Order the RTF version
About 3 pages (745 words)
Data type Summary

 


Types

One of the fundamental issues in programming languages is the "types" of objects or data primitives they afford to programmers. Fundamentally, these object types fall into the following categories:

  • Boolean--this is a type, sometimes abbreviated bool, for representing truth value, which can take the logical values True or False (sometimes represented as 1 and 0, but without the normal numeric connotation). A Boolean type typically cannot be converted to anything else.
  • Integer--this is a type, sometimes abbreviated int, for representing whole numbers, either positive of negative. The integer type has siblings short and long (sometimes called short int and long int), vide infra.
  • Floating point--this is a type, sometimes abbreviated float, used to represent rational numbers. The float type has siblings double and long double, vide infra.
  • Character--this is a type, sometimes abbreviated char, used to represent alphanumeric strings.

The basic integer object type in C, C++, Java, and other programming languages is called int. Generally, the specification of the programming language itself does not specify the size of an int--that depends on the hardware and on the compiler used. Thus, the size of an int may be said to be "implementation dependent," to mean that the creator of the compiler is free to choose this size given the constraints of the hardware and the needs of his intended market. On most contemporary PC systems, int is a 32-bit signed number; "signed" because it always has a positive or negative sign associated with it, to show whether a positive integer or a negative integer is being referred to. On larger systems, int may be a 64-bit signed number. Some programming languages also provide for types short and long--these are also implementation dependent, but the specification usually requires that int be no shorter than short and no longer than long.

The basic rational number object type is float, the floating-point type. There is no type for real numbers such as (because infinite fractional expansions cannot be handled on a computer), so real numbers are approximated by using float. Analogous to the int case, greater precision may be obtained by use of double and still greater by long double. The sizes of these types are generally not dictated by the programming language specification, and are compiler dependent--most commonly, float is a 32-bit IEEE 754 floating-point number, while double is a 64-bit IEEE 754 floating-point number.

The character object type char is related to the integer object type. Each character (such as letters a-z, A-Z, &, %, #, @, etc.) is encoded as an integer; there is a table or encoding scheme where an integer in a certain range represents a particular character. The encoding scheme used is called the character set. Early IBM mainframes used the EBCDIC character set with each character represented by an 8-bit integer; the ASCII character set, in much wider use, uses a 7-bit integer. The char data type traditionally used an 8-bit integer, even with ASCII, but newer languages like Java use an 16-bit Unicode character set, to allow for the use of special symbols, characters from languages other than English, and so on. It is important to note that the char type can hold numbers as well, as long as they are treated as mere strings rather than entities to be manipulated for computation.

A programming language is said to be "strongly typed" if it requires that all variables be defined as being of a certain type before they are first used in a program, and that no variable be used in a manner corresponding to a type other than the one it is declared as (such as declaring a variable to be a char, but then using it as an integer). A "weakly typed" language has the opposite quality and allows variables to be used without first being defined, and also may allow variables to be used in a maner inconsistent with their declarations. Java is an example of a strongly typed language, and C is an example of a weakly typed language. The advantage of strong typing is considered to be a reduced risk of careless mistakes on the part of programmers--because every variable must be declared before first use, a certain accounting of procedures and ideas is forced, which may be useful in larger programs with many variables that interact in complex ways. Strong typing is also considered to improve the security features of the language. Weak typing is the more traditional approach, and is preferred by some programmers for the greater freedom it affords them.

This is the complete article, containing 745 words (approx. 2 pages at 300 words per page).

More Information
  • View Types Study Pack
  • 16 Alternative Definitions
  • Search Results for "Types"
  • More Products on This Subject
    Coercion of Data Types
    Coercion of data types is a technique for converting data from one type to another; its purpose is ... more

    Simple Data Types
    Data are simply pieces of information, and an individual piece of information is a datum. Common us... more


    Ask any question on Data type and get it answered FAST!
    Answer questions in BookRags Q&A and earn points toward
    discounted or even FREE Study Guides and other BookRags products!
    Learn more about BookRags Q&A
    Copyrights
    Types from World of Computer Science. ©2005-2006 Thomson Gale, a part of the Thomson Corporation. All rights reserved.

    Join BookRagslearn moreJoin BookRags

    Join BookRagslearn moreJoin BookRags