Abstraction of memory access Flashcards

1
Q

What is a variable in terms of memory?

A

A method of storing information in your computer’s memory.

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

Define declaration:

A

Tells the compiler the name and type of something.

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

Define definition:

A

In addition to the declaration, it tells the compiler where it is stored in memory.

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

In C how would we find the the variable int x = 10; address?

A

&x (ampersand operator)

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

Why do we want a variable’s address?

A

C only allows pass by value and return by value.

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

What is pass by value?

A

When passing a variable into a function, a copy is always made.

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

How does the ampersand (&) operator overcome pass by value?

A

It allows us to pass the memory address of where data is stored instead.

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

What are pointer variables?

A

Variables that store memory addresses as their value (unsigned integers).

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

How do we refer to pointers in C?

A

By the data type of the thing they point to followed by an asterisk (*)

e.g. int * is a int pointer

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

How would you deference a pointer to a pointer?

A

Adding two asterisks to the pointer variable:

int i;
int *ptr_to_i = &i;
int **ptr_to_ptr_to_i = &ptr_to_i;

// i == **ptr_to_ptr_to_i;

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

What are arrays in C?

A

A block of continuous memory.

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

How do we keep track of the length of an array?

A

There is no .length() therefore we must manually keep track.

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

How are strings stored in C?

A

There is no string type in C, therefore contiguous blocks of chars in memory terminated by a null character (/0) is used.

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

How do we refer to a string in C?

A

The location of the first char in memory.

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

Is passing pointers the same as pass by reference?

A

No, because C just creates a copy of the pointer.

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