Tipe_Data_dalam_Pascal

Published on Oct 04, 2026

Tipe_Data_dalam_Pascal

Tipe_Data_dalam_Pascal - PDF to Podcast

Published on Oct 04, 2026

Description:

Welcome to Code Lantern, the show where we make programming basics feel less mysterious. I'm Maya. Today we're opening a lecture handout from STMIK Indonesia Banjarmasin about data types in Pascal. Budi, why should a beginner care about data types?
Data types usually determine the kind of value a variable can hold. Pascal provides simple and structured types, and if you need something new, you can define your own types, including enumerated types.
And the handout describes every data type as a structure with four properties: name, domain, how its members are named, and operations on that type.
Exactly. Pascal's built-in types are described that way, and the document calls them data structures because we can describe those four properties for them.
Let's start with the simple types.
The simple types listed are Integer for whole numbers, Char for characters, Boolean, and Real for real numbers. They're called simple because their values are automatic, meaning one single entity that can't be divided further.
What makes them abstract data types?
The handout says they can be viewed as abstract data types because they contain a set of values and a set of basic operations and relations defined on the type. Their algorithms are implemented using hardware instructions.Integer's domain is Z, the set of whole numbers. In Turbo Pascal-like implementations, examples include Shortint from minus 128 to 127, Integer from minus 32768 to 32767, Longint from minus 2147483648 to 2147483647, Byte from 0 to 255, and Word from 0 to 65535.
And the operators?
Arithmetic operators include star, plus, minus, slash, div, mod, and abs. Relational operators include less than, less than or equal, greater than, greater than or equal, not equal, and equal. Integer arithmetic on a computer is a subset of mathematical integers, and operations are exact, corresponding to arithmetic laws.
Now characters and Boolean values.
Char has a domain of ASCII or EBCDIC codes. Constants include 'A', 'Z', '#', '$', '&', 'a', and codes like #21 and #254. Operations include assignment, not equal, plus chr and ord.
So characters are stored as numeric codes.
Yes. Computers store character and nonnumeric data by assigning numeric codes to characters in a character set. Common standards are ASCII and EBCDIC. Characters are represented internally by binary codes, and comparison is done by the integer that represents the character. Two characters are equal if their codes are equal, and they can be sorted by code value.
Boolean next?
Boolean's domain is True and False. Constants are true and false. Logical operations are AND, OR, XOR, NOT, equal, and not equal. There are only two values; it can be represented by one bit, with 0 for false and 1 for true. On many systems, Boolean values are stored in a byte or word.
What about real numbers?
Real has domain R, the set of real numbers. Turbo Pascal implementations include Real, Single, Double, Extended, and Comp with different ranges. For example, Real ranges from about 2.9 times 10 to the 39th to 1.7 times 10 to the 38th, and Comp ranges from negative 2 to the 63rd plus 1 to 2 to the 63rd minus 1. Constants include 0, 3.2333, minus 89.0, 98787.6, 12E minus 2, and 1.5E17.Arithmetic operators are star, plus, minus, slash, and abs. Relational operators are less than, less than or equal, greater than, greater than or equal, and not equal. Real arithmetic is not exact; it has round-off error because computation uses only a finite number of digits.
That covers simple types. Now ordinal types.
Ordinal types have members that can be ordered. Every value has a predecessor and a successor. Ordinal types are divided into predefined ones, namely Integer, Char, and Boolean, and user-defined ones.In implementation, ordinal types are always limited. There's a lower bound with no predecessor and an upper bound with no successor.
What can users define?
Two main user-defined ordinal types: subrange and enumeration. A subrange is declared like Type T equals min dot dot max. Examples include huruf equals 'A' dot dot 'Z', digit equals '0' dot dot '9', tanggal equals 1 dot dot 31, bulan equals 1 dot dot 12, and tahun equals 1900 dot dot 3000.For type bulan equals 1 dot dot 12, the name is bulan, the domain is 1 through 12, constants are 1 through 12, and operators are those of the parent ordinal type, Integer. Pascal compilers change subrange values into the parent type.
And enumeration?
Enumeration is declared like Type T equals, in parentheses, constant1, constant2, and so on through constantN. An example is Type NamaHari equals senin, selasa, rabu, kamis, jum'at, sabtu. Another is Type NamaBulan equals Januari, Februari, Maret, April, and so on.The operations for an enumerated type are those of its parent ordinal type, Integer, because the Pascal compiler converts enumeration values into integer values.
Now structured types. What's first?
Array is a well-known structure because many languages implement it. An array is a homogeneous structure containing components of the same type. In Pascal: Type T equals array, lmin dot dot lmax, of T0. Examples include Type Card equals array 1 dot dot 52 of integer, and Type JumlahMuridSD equals array 1 dot dot 6 of integer.
So a Card array has 52 integer elements.
Yes. Its name is Card, its domain is a tuple of 52 elements, each containing an integer. Constants might be values like 15, 67, and 0. Arithmetic and relational operations apply to each integer element, but operators for the Card type itself must be defined by the programmer to control its behavior according to specification.
What about records?
A record combines elements of other types, sometimes structured types, into a new form. In mathematics, this is like a complex number made of two real numbers, or coordinates made of two or more real numbers. The domain is the set of all possible combinations of the component values.Pascal syntax: Type T equals record, s1 of T1, s2 of T2, through sN of TN, end. Example: type komplek equals record re real, im real, end. Another: type tanggal equals record hari 1 dot dot 31, bulan 1 dot dot 12, tahun 1900 dot dot 3000, end.For type titik equals record x real, y real, end, the name is Titik, the domain is a pair of real values, constants might be 5.0, 67, and 9, and each component uses the operations of its component type. Operators for titik must be defined by the programmer.
And sets?
A set is declared as Type T equals set of T0. A variable x of type T holds sets of elements of type T0. The set of all subsets whose elements are from T0 is called the powerset of T0; type T can contain the powerset of base type T0. Example: Type nodes equals set of 1 dot dot 10. Its domain is the powerset of 1 through 10; constants include the set containing 1, the set containing 2 and 3, and the set containing 4, 7, and 10.Set operations include star for intersection, plus for union, minus for difference, and in for membership.
And finally, user-defined data structures.
In Pascal, creating a data structure means the programmer specifies the component types. The programmer must specify the four properties: name, domain, naming of members, and operations. A declaration like Complex equals record re, im of real, end, is not yet a full data structure because it only has a name and domain. A data structure must also include the set of operations applied to the data.For complex numbers, basic operations might include SetComplex for initialization, GetComplex to retrieve components, ReturnRe and ReturnIm to return real and imaginary parts, and AddComplex, SubComplex, MulComplex, and DivComplex for arithmetic. These operations are implemented with functions and procedures to guarantee behavior according to specification and invariants.
That's a helpful reminder that a type isn't just a shape; it's a contact for behavior.
The handout shows one implementation: Procedure SetComplex, var C complex, r and i real, begin C.re equals r, C.im equals i, end.
Let's wrap up.
To review: Pascal data types include simple types such as Integer, Char, Boolean, and Real; ordinal types, which can be ordered and include predefined and user-defined subrange and enumeration; and structured types such as array, record, set, and file.
I like how the hierarchy makes it easier to see what a variable can hold and what operations make sense.
And the key idea from the source is that every data type can be described by its name, domain, members, and operations, whether it's built into Pascal or defined by the programmer.
Thanks for listening to Code Lantern. Next time, we'll keep exploring programming fundamentals.