Copyright HébergementWebs.com - License GPL

Pascal - Data types

Paschal tutorial   2020-11-21 02:18:47

Pascal - Data types The data types of an entity indicate the direction, the constraints, the possible values, the operations, the functions and the storage mode associated with it. The integer, real, boolean, and character types are called standard data types. Data types can be classified into scalar, pointers, and structured data types. Examples of scalar data types are integer, real, boolean, character, subrange, and enumerated. Structured data types are made up of scalar types; for example, tables, records, files and sets. We"ll discuss pointer data types later. Pascal data types Pascal data types can be summarized as below in the following diagram - Type declarations The type declaration is used to declare the data type of an identifier. The syntax of the dicetype claration is - type-identifier-1, type-identfier-2 = type-specifier; For example, the following declaration sets the variables days and age as integer type, yes and true as boolean type, name and city as string type, fees and expenses as actual type. type days, age = integer; yes, true = boolean; name, city = string; fees, expenses = actual; Integer types The following table gives you details of the standard integer types with their storage sizes and value ranges used in Object Pascal - Type Minimum Maximum Format Integer -2147483648 2147483647 32 bits signed Cardinal 0 4294967295 32-bit unsigned Shortint -128 127 signed 8 -bit Smallint -32768 32767 16-bit signed Longint - 2147483648 2147483647 32 bits signed Int64 -2 ^ 63 2 ^ 63 - 1 64-bit signed byte 0 255 8 bits unsigned Word 0 65535 unsigned 16 bits Long word 0 4294967295 32bit unsigned Constants Using constants makes a program more readable and helps to keep special quantities in one place at the start of the program. Pascal allows numeric, logical, string and character constants. Constants can be declared in the declaration part of the program in spec.if using the const declaration. The syntax for the constant type declaration is as follows - const Identifier = contant_value; Here are some examples of constant declarations - VELOCITY_LIGHT = 3.0E = 10; PIE = 3.141592; NAME = "Stuart Little "; CHOICE = yes; OPERATOR = "+ "; All constant declarations must be given before the variable declaration. Enumerated types Enumerated data types are user-defined data types. They allow you to specify values ​​in a list. Only assignment operators and relational operators are allowed on the enumerated data type. Enumerated data types can be declared as follows - type enum-identifier = (item1, item2, item3, ...) Here some examples of declarations of types listed - type SUMMER = (April, May, June, July, September); COLORS = (red, green, blue, yellow, magenta, cyan, black, white); TRANSPORT = (bus, train, plane, boat); The order in which the elements are listed in the domain of an enumerated type defines the order of the elements. For example, in the merated type SUMMER, April comes before May, May comes before June, and so on. The domain of enumerated type identifiers cannot consist of numeric constants or characters. Sub-range types Sub-range types allow a variable to take values ​​within a certain range. For example, if the age of voters should be between 18 and 100, a variable named age could be declared as - var age: 18 ... 100; We"ll look at the variable declaration in detail inthe next section. You can also define a sub-range type using the type declaration. The syntax for declaring a subrange type is as follows - type subrange-identifier = lower-limit ... upper-limit; Here are some examples of sub-range type declarations - const P = 18; Q = 90; type Number = 1 ... 100; Value = P ... Q; Sub-range types can be created from a subset of an enumerated type already defined, for example - type month = (Jan, Feb, Mar, April, May, June, July, August, September, October, November, December); Summer = April ... August; Winter = October ... December;