Programming Languages: Data Structures, Records, Lists, and Pointers

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

flashcard set

Earn XP

Description and Tags

Flashcards covering associative arrays, record types, tuple types, list operations across paradigms, and pointer memory dynamics based on lecture notes.

Last updated 1:36 PM on 8/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

24 Terms

1
New cards

What are the core limitations of traditional arrays that associative arrays and record types address?

Traditional arrays rely on numerical indices and require homogeneous data types. Associative arrays solve this by allowing user-defined key indexing, while record types allow grouping heterogeneous data elements using static names.

2
New cards

How does key storage differ between traditional arrays and associative arrays?

Traditional array indices are implicit numerical positions, whereas associative array user-defined keys must be explicitly stored alongside the values.

3
New cards

In Perl, why does the variable prefix change from % to $ when referencing a specific hash value?

The prefix changes from % (used for the hash variable identifier) to $ because the specific value returned from the hash lookup is a scalar.

4
New cards

Which Perl built-in functions are used to remove a key-value pair and test for key existence in a hash?

The delete function is used to remove a key-value pair (e.g., delete $salaries{"Gary"}), and the exists function is used to test whether a key exists (e.g., exists $salaries{"Shelly"}).

5
New cards

How does key type flexibility for associative arrays vary among Perl, PHP, Swift, and Python/Ruby?

Perl strictly requires keys to be strings. PHP operates in dual mode allowing strings or integers. Swift enforces strict typing where keys must be of one specific type. Python and Ruby offer maximum flexibility, allowing keys to be any object.

6
New cards

What happens to the hash function and key entries when an associative array dynamically resizes?

The hash function does not change. Instead, more bits of the 32-bit hash value are used, which requires only half of the existing entries to move to new memory buckets.

7
New cards

What is the definition of a record data type?

A record is an aggregate of data elements identified by names and accessed through memory offsets from the beginning of the structure.

8
New cards

How did COBOL structure record declarations when it introduced them in the early 1960s?

COBOL used hierarchical level numbers (such as 01, 02, 05) to structure fields and PICTURE clauses (e.g., PICTURE IS X(20)) to specify exact byte formatting.

9
New cards

What is the difference between a fully qualified reference and an elliptical reference in COBOL?

A fully qualified reference explicitly lists all intermediate enclosing record names (e.g., FIRST OF EMPLOYEE-NAME OF EMPLOYEE-RECORD), whereas an elliptical reference omits intermediate record names if the field remains unambiguous (e.g., FIRST OF EMPLOYEE-RECORD).

10
New cards

Why do modern programming languages avoid dynamic subscripts for accessing record fields?

Using dynamic subscripts for records would disallow compile-time type checking and significantly reduce execution speed.

11
New cards

In C/C++, what syntactic sugar operator combines pointer dereferencing and record field access?

The -> operator combines pointer dereferencing and field referencing into one symbol, making (*p).age equivalent to p->age.

12
New cards

Why do record types incur zero performance penalty during program execution?

The compiler creates a static compile-time descriptor containing field names, types, and relative memory offsets. Because field offsets are fully resolved prior to runtime, no record descriptor exists at run-time.

13
New cards

What is a tuple type, and how does it differ from a record type?

A tuple is a heterogeneous data aggregate without field names. Elements are accessed by positional order or pattern matching rather than by named identifiers.

14
New cards

What primary purpose does tuple immutability serve in Python?

It enforces write-protection, allowing lists/arrays to be passed as parameters to external functions while ensuring the function cannot modify the underlying data.

15
New cards

How can a Python programmer modify the contents of an immutable tuple?

The programmer converts the tuple to a mutable list using list(), modifies the list elements, and then converts it back into a tuple using tuple().

16
New cards

How does the quote operator ' change the way the Lisp/Scheme interpreter evaluates a list?

Without the quote operator, the interpreter evaluates the first list item as a function name and subsequent items as parameters. With the quote operator ', the interpreter treats the list as a literal data structure.

17
New cards

What are the primary functions for list deconstruction and construction in Scheme?

CAR returns the first element, CDR returns the tail (remainder), CONS prepends an element to a list, and LIST constructs a new list from its parameters.

18
New cards

How do ML lists differ from Scheme lists in terms of syntax and type strictness?

ML lists use square brackets [] with comma-separated elements and are strictly homogeneous (all elements must be the same type). Scheme lists use parentheses () with space-separated elements and are heterogeneous.

19
New cards

What are the ML equivalents of Scheme's CAR, CDR, and CONS operations?

hd (head) corresponds to CAR, tl (tail) corresponds to CDR, and :: (binary infix operator) corresponds to CONS.

20
New cards

What is an anonymous variable in dynamic memory management?

An anonymous variable is a heap-dynamic variable that does not have an identifier (name) and can only be accessed through a pointer.

21
New cards

What defines a dangling pointer and why is it dangerous?

A dangling pointer contains the address of a dynamic variable that has already been deallocated. It is dangerous because accessing it can lead to data corruption, type violations, and program crashes.

22
New cards

How does a lost variable (memory leak) occur?

A lost variable occurs when a pointer pointing to an allocated heap-dynamic variable is reassigned to another address before the original target memory is explicitly deallocated, leaving unreachable garbage on the heap.

23
New cards

How is address scaling calculated in pointer arithmetic for the expression *(ptr + index)?

The memory jump is calculated by scaling index by the physical byte size of the base data type: Jump=index×size(Type)\text{Jump} = \text{index} \times \text{size}(\text{Type}).

24
New cards

In C/C++, how are array subscripting and pointer dereferencing mathematically linked?

An array name without a subscript acts as a pointer to its first element, making *(ptr + index) mathematically and functionally identical to list[index].