This article compares a large number of
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
s by tabulating their
data type
In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or interpreter how the programmer intends to use the data. Most progra ...
s, their
expression
Expression may refer to:
Linguistics
* Expression (linguistics), a word, phrase, or sentence
* Fixed expression, a form of words with a specific meaning
* Idiom, a type of fixed expression
* Metaphorical expression, a particular word, phrase, ...
,
statement, and
declaration syntax, and some common operating-system interfaces.
__TOC__
Conventions of this article
Generally, ''var'', , or is how variable names or other non-literal values to be interpreted by the reader are represented. The rest is literal code.
Guillemet
Guillemets (, also , , ) are a pair of punctuation marks in the form of sideways double chevrons, and , used as quotation marks in a number of languages. In some of these languages "single" guillemets, and , are used for a quotation inside a ...
s ( and ) enclose optional sections. indicates a necessary (whitespace) indentation.
Note that the tables are not sorted lexicographically ascending by programming-language name by default, and that some programming languages have entries in some tables but not others.
Type identifiers
Integer
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
s
* The ''standard'' constants and can be used to determine how many s and s can be usefully prefixed to and . The actual sizes of , , and are available as the constants , , and etc.
* Commonly used for characters.
* The ALGOL 68, C and C++ languages do not specify the exact width of the integer types , , , and (
C99
C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard. It extends the previous version ( C90) with new features for the language and the standard library, and helps imp ...
,
C++11
C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versio ...
) , so they are implementation-dependent. In C and C++ , , and types are required to be at least 16, 32, and 64 bits wide, respectively, but can be more. The type is required to be at least as wide as and at most as wide as , and is typically the width of the word size on the processor of the machine (i.e. on a 32-bit machine it is often 32 bits wide; on 64-bit machines it is sometimes 64 bits wide).
C99
C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard. It extends the previous version ( C90) with new features for the language and the standard library, and helps imp ...
and
C++11
C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versio ...
also define the exact-width types in the
stdint.h header. See
C syntax#Integral types for more information. In addition the types and are defined in relation to the address size to hold unsigned and signed integers sufficiently large to handle array indices and the difference between pointers.
* Perl 5 does not have distinct types. Integers, floating point numbers, strings, etc. are all considered "scalars".
* PHP has two arbitrary-precision libraries. The BCMath library just uses strings as datatype. The GMP library uses an internal "resource" type.
* The value of is provided by the
intrinsic function.
*
ALGOL 68
ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously ...
G's runtime option can set precision for s to the required "number" significant digits. The ''standard'' constants and can be used to determine actual precision.
*
COBOL
COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily ...
allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "", for example, would require a signed variable of four decimal digits precision. If specified as a binary field, this would select a 16-bit signed type on most platforms.
*
Smalltalk
Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by ...
automatically chooses an appropriate representation for integral numbers. Typically, two representations are present, one for integers fitting the native word size minus any tag bit () and one supporting arbitrary sized integers (). Arithmetic operations support polymorphic arguments and return the result in the most appropriate compact representation.
*
Ada range types are checked for boundary violations at run-time (as well as at compile-time for static expressions). Run-time boundary violations raise a "constraint error" exception. Ranges are not restricted to powers of two. Commonly predefined Integer subtypes are: Positive (
range 1 .. Integer'Last
) and Natural (
range 0 .. Integer'Last
). (8 bits), (16 bits) and (64 bits) are also commonly predefined, but not required by the Ada standard. Runtime checks can be disabled if performance is more important than integrity checks.
*
Ada modulo types implement modulo arithmetic in all operations, i.e. no range violations are possible. Modulos are not restricted to powers of two.
* Commonly used for characters like Java's char.
* in PHP has the same width as type in C has on that system.
*
Erlang is dynamically typed. The type identifiers are usually used to specify types of record fields and the argument and return types of functions.
* When it exceeds one word.
Floating point
In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be r ...
* The ''standard'' constants and can be used to determine how many s and s can be usefully prefixed to and . The actual sizes of , , and are available as the constants , and etc. With the constants , and available for each type's
machine epsilon
Machine epsilon or machine precision is an upper bound on the relative approximation error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the sub ...
.
* declarations of single precision often are not honored
* The value of is provided by the
intrinsic function.
*
ALGOL 68
ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously ...
G's runtime option can set precision for s to the required "number" significant digits. The ''standard'' constants and can be used to determine actual precision.
* These
IEEE
The Institute of Electrical and Electronics Engineers (IEEE) is a 501(c)(3) professional association for electronic engineering and electrical engineering (and associated disciplines) with its corporate office in New York City and its operati ...
floating-point types will be introduced in the next COBOL standard.
* Same size as on many implementations.
* Swift supports 80-bit
extended precision
Extended precision refers to floating-point number formats that provide greater precision than the basic floating-point formats. Extended precision formats support a basic format by minimizing roundoff and overflow errors in intermediate values ...
floating point type, equivalent to in C languages.
Complex number
In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the for ...
s
* The value of is provided by the
intrinsic function.
* Generic type which can be instantiated with any base floating point type.
Other variable types
* specifically, strings of arbitrary length and automatically managed.
* This language represents a boolean as an integer where false is represented as a value of zero and true by a non-zero value.
* All values evaluate to either true or false. Everything in ' evaluates to true and everything in ' evaluates to false.
* This language does not have a separate character type. Characters are represented as strings of length 1.
* Enumerations in this language are algebraic types with only nullary constructors
* The value of ' is provided by the
intrinsic function.
Derived types
Array
An array is a systematic arrangement of similar objects, usually in rows and columns.
Things called an array include:
{{TOC right
Music
* In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
* In most expressions (except the
sizeof
sizeof is a unary operator in the programming languages C and C++. It generates the storage size of an expression or a data type, measured in the number of ''char''-sized units. Consequently, the construct ''sizeof (char)'' is guaranteed to be ...
and operators), values of array types in C are automatically converted to a pointer of its first argument. See
C syntax#Arrays for further details of syntax and pointer operations.
* The C-like
''type'' x[]
works in Java, however
''type''[] x
is the preferred form of array declaration.
* Subranges are used to define the bounds of the array.
* JavaScript's array are a special kind of object.
* The clause in COBOL does not create a ''true'' variable length array and will always allocate the maximum size of the array.
Other types
* Only classes are supported.
* s in C++ are actually classes, but have default public visibility and ''are'' also
POD objects. C++11 extended this further, to make classes act identically to POD objects in many more cases.
* pair only
* Although Perl doesn't have records, because Perl's type system allows different data types to be in an array, "hashes" (associative arrays) that don't have a variable index would effectively be the same as records.
* Enumerations in this language are algebraic types with only nullary constructors
Variable and constant declarations
* Pascal has declaration blocks. See
functions.
* Types are just regular objects, so you can just assign them.
* In Perl, the "my" keyword scopes the variable into the block.
* Technically, this does not declare ''name'' to be a mutable variable—in ML, all names can only be bound once; rather, it declares ''name'' to point to a "reference" data structure, which is a simple mutable cell. The data structure can then be read and written to using the and operators, respectively.
* If no initial value is given, an invalid value is automatically assigned (which will trigger a run-time exception if it used before a valid value has been assigned). While this behaviour can be suppressed it is recommended in the interest of predictability. If no invalid value can be found for a type (for example in case of an unconstraint integer type), a valid, yet predictable value is chosen instead.
* In Rust, if no initial value is given to a or variable and it is never assigned to later, there is a
"unused variable" warning If no value is provided for a or or variable, there is an error. There is
error for non-uppercase variables. After it is defined, a variable can only be assigned to in an block or function.
Control flow
In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an '' ...
Conditional
Conditional (if then) may refer to:
* Causal conditional, if X then Y, where X is a cause of Y
* Conditional probability, the probability of an event A given that another event B has occurred
*Conditional proof, in logic: a proof that asserts a ...
statements
* A single instruction can be written on the same line following the colon. Multiple instructions are grouped together in a