Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pascal (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Data types=== A Type Declaration in Pascal is used to define a range of values which a variable of that type is capable of storing. It also defines a set of operations that are permissible to be performed on variables of that type. The predefined types are: {| class="wikitable" |- ! Data type ! Type of values which the variable is capable of storing |- | [[integer (computer science)|integer]] | integer (whole) numbers |- | [[floating-point arithmetic|real]] | floating-point numbers |- | [[Boolean type|Boolean]] | the values True or False |- | [[character (computing)|char]] | a single character from an ordered character set |- | [[set (computer science)|set]] | equivalent to an array of [[Boolean type|Boolean]] values |- | [[Array data type|array]] | a countable group of any of the preceding data types, of records, or of other arrays |- | [[Record (computer science)|record]] | A collection of any of the preceding data types or of other records |- | [[string (computer science)|string]] | a sequence or "string" of characters is declared as a "packed array of char" with a starting index of 1. These can be assigned string constants and individual characters can be accessed as elements of the array. |} The range of values allowed for the basic types (except Boolean) is implementation defined. Functions are provided for some data conversions. For conversion of <code>real</code> to <code>integer</code>, the following functions are available: <code>round</code> (using [[Rounding#Rounding_half_away_from_zero|rounding half away from zero]]) and <code>trunc</code> (rounds towards zero). The programmer has the freedom to define other commonly used data types (e.g. byte, string, etc.) in terms of the predefined types using Pascal's type declaration facility, for example :<syntaxhighlight lang="pascal"> type byte = 0..255; signed_byte = -128..127; string = packed array[1..255] of char; </syntaxhighlight> Often-used types like byte and string are already defined in many implementations. Normally the system will use a [[Word (computer architecture)|word]] to store the data. For instance, the {{code|byte}} type may be stored in a machine integer - 32 bits perhaps - rather than an [[8-bit computing|8-bit]] value. Pascal does not contain language elements that allow the basic storage types to be defined more granularly. This capability was included in a number of Pascal extensions and follow-on languages, while others, like [[Modula-2]], expanded the built-in set to cover most machine data types like 16-bit integers. The {{code|packed}} keyword tells the compiler to use the most efficient method of storage for the structured data types: sets, arrays and records, rather than using one [[Word (computer architecture)|word]] for each element. Packing may slow access on machines that do not offer easy access to parts of a word.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)