User-defined Data Types

Part of A2 Computer Science, in case you were wondering. I'm not going to put pseudocode examples here.

User-defined data types are exactly what the name suggests. If an integer/string/boolean/whatever other data type fails to meet your needs while writing a program, then thou have been granted permission to write your own data types.

Categories

Broadly speaking, there are two kinds of user-defined data types. You have:

  1. Composite data types

    Composite data types are derived from other data types built into your programming language of choice OR another custom data type you may have defined before. For example, a user-defined data type that makes use of strings or integers would be composite.

  2. Non-composite data types

    Non-composite data types are not derived from any other data type.

Enumerated Data Types

Enumerated data types stem from the non-composite category. It is a list of pre-defined data (remember, non-composite).

This didn't make much sense to me at first, but after a quick read online, I found this resource which cleared things up:

"Enums, or enumerated types, are a list of constant values with developer-friendly names. They're used in programming to commonly used to establish a set of predefined values that a variable can take.

For example, you could have an enum called "Fruits," with a list of possible fruits that the application understands. This is the key difference between just using a string to represent this variable --- a string can have infinite possible values, while this enum can only have three [apples, oranges, bananas]."

That makes a lot more sense. I've definitely used strings for this sort of purpose in the past, so it's nice to know that this exists.

It's important to note that any data in an enumerated data type does not derive from another data type. If you have words in your enum, then those words are not strings!

Pointer Data Types

Pointers are a data type themselves (and they are non-composite). When defining one, the type of data it will reference must be specified. If your pointer will point to integers, then you must specify that the pointer will point to integers.

You can then decalare a variable whose type is the pointer you just defined. If you assign to this variable another variable (using the appropriate syntax), then it will give you the memory address of the variable you just passed.

If instead you'd like to access the data at this memory location, you can use a technique known as dereferencing; the way you do this depends on your programming language.

If this explanation sounds a bit vague, I found this nice video on Youtube: you will never ask about pointers again after watching this video. The title isn't entirely true, but it did make a fair bit of sense.

Sets

A set is a composite data type. It's also your standard mathematical set, on which you can perform your standard set operations (i.e. unions/intersections).

Classes

If I remember, I shall update this section later on.

This article was written on 2024-08-07. If you have any thoughts, feel free to send me an email with them. Have a nice day!