0% found this document useful (0 votes)
33 views7 pages

13,3user Defined Data Types

This document discusses different types of data types in programming languages, including built-in, user-defined, composite, and non-composite data types. It provides examples of enumerated data types, pointer data types, sets, and classes to illustrate user-defined composite and non-composite data types. Classes are mentioned as being covered in more depth in later chapters.

Uploaded by

mohidtahir8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views7 pages

13,3user Defined Data Types

This document discusses different types of data types in programming languages, including built-in, user-defined, composite, and non-composite data types. It provides examples of enumerated data types, pointer data types, sets, and classes to illustrate user-defined composite and non-composite data types. Classes are mentioned as being covered in more depth in later chapters.

Uploaded by

mohidtahir8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

13.

1 User-
defined data
types

Zain Merchant
Zain Merchant
Zain Merchant
Data Types
Built-in data types
Remember, for each built-in data type:
• the programming language defines the range of possible values that can
be assigned to a variable when its type has been chosen.
• the programming language defines the operations that are available for
manipulating values assigned to the variable.

User-defined data types


The term ‘user’ is regularly applied to someone who is provided with a ‘user
interface’ by an operating system – the ‘user’ is the person supplying input to a
running program and receiving output from it.
However, when writing a program, a programmer becomes a ‘user’ of a
programming language. The term user-defined data type applies to this latter type
of user.
A user-defined data type is a data type for which the programmer has included the
definition in the program. Once the data type has been defined, variables can be
created and associated with the user-defined data type. Note that, although the
user-defined data type is not a built-in data type, using the user-defined data type
is only possible if a programming language offers support for the construct.

Non-composite data types


A non-composite data type can be defined without referencing another data type.
It can be a primitive type available in a programming language or a user-defined
data type. Non-composite user-defined data types are usually used for a special
purpose.
We will consider enumerated data types for lists of items and pointers to data in a
computer’s memory.

Enumerated data type


An enumerated data type contains no references to other data types when it is
defined. In pseudocode, the type definition for an enumerated data type has this
structure:

For example, a data type for months of the year could be defined as:

Zain Merchant
Then the variables thisMonth and nextMonth of type Tmonth could be defined as:

Pointer data type


A pointer data type is used to reference a memory location. This data type needs
to have information about the type of data that will be stored in the memory
location. In pseudocode the type definition has the following structure, in which ^
shows that the type being declared is a pointer and <Typename> is the type of
data to be found in the memory location, for example INTEGER or REAL, or any
user-defined data type.

For example, a pointer for months of the year could be defined as follows:

Zain Merchant
It could then be used as follows:

If the contents of the memory location are required rather than the address of the
memory location, then the pointer can be dereferenced. For example, myMonth
can be set to the value stored at the address monthPointer is pointing to:

Composite data types


A data type that refers to any other data type in its type definition is a composite
data type. The data type for record was introduced as a composite data type
because it refers to other data types.

Other composite data types include sets and classes.

Sets
A set is a given list of unordered elements that can use set theory operations such
as intersection and union. A set data type includes the type of data in the set. In
pseudocode, the type definition has this structure:

Zain Merchant
The variable definition for a set includes the elements of the set.

A set of vowels could be declared as follows:

Classes
A class is a composite data type that includes variables of given data types and
methods (code routines that can be run by an object in that class). An object is
defined from a given class; several objects can be defined from the same class.
Classes and objects will be considered in more depth in later chapter. Try asking
me (Zain Merchant) in class, I just might explain during lecture of this chapter.

Zain Merchant

You might also like