Abstractions of memory access

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1

What does it mean that C gives direct access to memory?

C allows direct manipulation of memory using pointers, and every memory byte has a unique address.

2

How does C's memory management differ from higher-level languages like Java?

C requires manual memory management, unlike Java which uses automatic garbage collection.

3

What is the purpose of memory protection by the OS?

It prevents crashes from invalid memory access by isolating memory spaces.

4

What is a variable in C?

An abstraction for a memory location used to store data.

5

What does int h2g2 = 42; do in memory?

Allocates 4 bytes and stores the value 42.

6

How do you get the memory address of a variable in C?

Use the address-of operator: &variable.

7

What is the difference between declaration and definition in C?

Declaration introduces a name and type; definition allocates memory.

8

What value might an uninitialized variable contain?

Garbage (undefined/random value).

9

How does C handle function arguments by default?

By value — the function receives a copy of the argument.

10

How do you modify a variable inside a function in C?

Pass its address using a pointer and dereference it inside the function.

11

What does a pointer store?

The memory address of another variable.

12

How do you get the value a pointer points to?

Dereference it using *pointer

13

What is a pointer to a pointer?

A variable that stores the address of another pointer, e.g., int **pp.

14

How is an array represented in memory in C?

As a contiguous block of memory, with the array name pointing to the first element.

15

How does pointer arithmetic work with arrays?

arr[i] is equivalent to *(arr + i)

16

What happens when you cast an array to another pointer type, like (char*)arr?

You can access the memory byte by byte, but incorrect casting may misalign data.

17

How are strings represented in C?

As null-terminated character arrays (char[] ending with \0).

18

What does %s in printf expect?

A char* to a null-terminated string

19

How do you modify a variable using a function and pointers?

Pass the variable's address:

void change(int *p) { *p = 7; }  
change(&x);  

20

When a pointer is passed to a function, what actually gets passed?

A copy of the address (pass-by-value still applies).

21

Why shouldn't you return a pointer to a local variable?

Because the variable’s memory is deallocated after the function ends, making the pointer invalid.