Week 5 - Complex Data Types & Memory Flashcards

1
Q

What is a primitive data type?

A

The basic types of data which come default with the programming language.

Eg: boolean, float/real, int, string etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the difference between an array and a class/record?

A

A class/record is used to define the blueprint of a general things. This doesn’t contain any actual values.

However, an array is used for storing multiple variables and values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Pass by Value

A

Takes a copy of the variable and passes it to the called function or procedure.
Passes only the value of the variable.

Like downloading Word Doc to edit on your own. Changes made are independent of the main doc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Pass by Reference

A

Takes a copy of the link to the content passes it to the called function or procedure.
Passes the actual variable and value.

Like emailing a link to a Google Docs which allows for everyone to make changes to the main document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the main parts of memory?

A

The code area, global variables, the stack and the heap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are pointers and references used for?

A

Pointers/references are found on the stack, and link to a value or variable on the heap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you assign values to fields once you define a type?

A

No. Because you need to first initialise the values.

This is where you have the placeholder values, so that you can then pass values into that class/function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the main ways of using complex and custom data types in Ruby?

A

Classes/records, structs & modules/enumerations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The Stack

A

A part of the computer memory responsible for storing function calls and local variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The Heap

A

It’s a large pool of memory where the running program can request chunks of memory.
This is typically used alongside pointers and references on the stack to point to memory on the heap.

This is typically called dynamic allocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Code Area

A

Where class definitions go and main code goes.

This area of memory is fixed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Global Variables

A

Where all global variables and constants accessible to all functions are stored in the computer memory.

This area of memory is fixed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the difference between the stack and the heap?

A

The stack is a linear data structure, whereas the heap is a hierarchical data structure.

The stack is fixed, whereas the heap is dynamic and can change throughout the runtime of a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Enumerations

A

Modules define an enumeration which is a custom data type.

They are not not like classes or structs because they are created as a set of constants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Attributes

A

Used to define data/special characteristics of a class/record. They make up the blueprint of our class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Methods

A

Functions/procedures used to handle the behaviour.

17
Q

Instance/Object

A

Is a concrete occurrence of any object. This is the same thing as a token.

Eg: a program may have a class/object named Animal, but there could be many instances of Animal, such as lion, cat, and dog.

18
Q

What’s the difference between instance and class?

A

Class is the blueprint for an object, whereas the instance is a specific token of that class.

If our class is animals, then an instance could be dog.

19
Q

How do we access enumerations?

A

Access by using ‘Class name here’::’value’

20
Q

How do we add values onto the end of an array?

A

Use: Array &laquo_space;value

21
Q

Stack Overflow

A

Occurs when the space on the stack has exceeded and the operating system will stop and complain to fix this issue.

22
Q

What does .new() do?

A

Allows for a programmer to allocate memory on the heap.

23
Q

Objects

A

An abstraction used to represent objects in the real world such as cars, birds, trees etc.

Objects have 2 features which are data & behaviour.

Eg: colour, name, speed
Eg: drive, stop, accelerate

24
Q

Why do we need to use the heap?

A

It allows for programmers to have more control over the computer memory being used.

25
Q

What’s the difference between a pointer and a reference?

A

A pointer has the freedom to be assigned to the location of a variable.

References are directly put onto a variable, meaning that you can now call the variable two ways, by the variable name or the reference name.