1/13
Flashcards reviewing memory, pointers, and records in C.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Byte Addressable Memory
Computer memory is usually byte addressable, meaning it can be thought of as an array of bytes, each with a unique address.
Word Size
In this course, a word is assumed to be 32 bits (4 bytes) long.
Variable Aspects
A variable has a symbolic name, a value it contains, and an address where it resides in memory.
LHS vs RHS in Assignment Statements
On the RHS of an assignment, we fetch the value stored at the address of the variable; on the LHS, we use the address of the variable as the place to store the result.
Pointers
They solve the problem of multiple functions working on the same object by allowing programmers to pass memory addresses as values.
Address-of Operator (&)
The &
unary operator returns the address of its operand.
Dereference Operator (*)
On the RHS of a statement, the *
unary operator returns the value stored at the address contained within its operand.
Arrays vs Records
Arrays model collections of values of the same type, while records model entities with values of different types.
Record
A compound item, unlike an array (which is homogeneous), it is heterogeneous. Components are called fields. Each field is identified using a name (not an index) and holds different properties of a single entity
struct
Used to define a new record type in C.
malloc function
Used to allocate memory dynamically from the heap.
sizeof function
Tells us how many bytes a record occupies.
Arrow (->) Operator
Selects an attribute or field of the record when using a pointer to the struct.
Dot (.) Operator
Accesses the fields of a struct directly (not via a pointer).