121 Week 6 - Memory and Pointers Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Byte accessible memory

A

Each item in memory is the size of a byte and has a unique address which it can be identified by.

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

Words

A

A set number of items in memory which are grouped together.
Word size can differ between machines but are often 32 bit (4 bytes) or 64 bit (8 bytes).
Addresses for words will go up in multiples of the bytes size - 4 byte word addresses would go up by 4 each time.

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

Big endian format

A

The byte with the lowest address stores the most significant byte.

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

Little endian format

A

The byte with the lowest address stores the leastsignificant byte.

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

Aspects of a variable

A

A name, a value which it contains and an address for where the variable is stored in memory.

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

Pointer

A

A variable that holds a memory address.
Can be thought of as pointing to that location in memory

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

Declaring a pointer

A

Pointers are declared by stating the data type of the pointer, then a * to indicate it is a pointer then the name of the pointer then its value.
E.g.,
int x = 3;
int *pX = &x;
will store the address of the character variable x. The & means get address of.

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

Dereferencing

A

Dereferencing lets you get the value of what is being pointed to rather than just its address. It is done by having a * before the pointer name.
e.g.,
int x = 3;
int *pX = &x;
printf(ā€œ%dā€, *pX);
will output 3, not the address of x.

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

Record

A

A compound item that can store multiple components called fields which can be of different data types to each other.
Each field is identified using a name rather than an index.
Records hold multiple properties of a single item.

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

Records in C

A

Records in C can be defined using structs
e.g.,
typedef struct person {
char name[20];
int age;
} Person

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

Allocating space for records

A

Allocating space can be done using malloc() which takes a size in bytes as an argument then allocates this amount of memory in the heap and returns a pointer to its address.
e.g.,
Person* pt = malloc (sizeof (Student) )
sizeof() returns the size in bytes of an item.

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

Accessing fields

A

Fields of an array can be accessing using the . or -> operators
Fields from a record can be accessed using recordName.fieldName
Fields from a record stored as a pointer to it can be accessed using recordName->fieldName

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