Lecture 3 - Memory & Pointers Flashcards
(48 cards)
What is memory?
Part of the computer which is used to store data and program instructions for retrieval.
What can we think of memory as
a sorting cabinet, where each box stores the value and the label is the variable name
What notion do we have in memory?
A notion of spatial locality. This is an important property of which caches make use of. This is when a line of memory is fetched,so close by data that may be needed soon can be loaded quickly (is cached).
- We are making a guess as to what data will be needed
How long are addresses in 64 bit architecture?
64 bits or 8 bytes
How big is a memory addressed by an address?
a byte (8 bits)
How many addresses can a 64 bit architecture have ?
2^64 addresses to bytes
Do we need to get the full byte to modify a single bit ?
YES
What doe (1 «_space;3) mean ?
A left shift (multiplication by 2).
What does & do?
Gets the address of a variable -> pointer.
what is sizeof()
A function that gets the size of a variable in bytes
What is a pointer?
A variable which has the value , which is the address of a memory location. It essentially points to where the data is.
What is * called.
The dereference operator?
What does * do?
It gets the value at the address.
Is every pointer the same size?
YES
How big are pointers in 64 bit architecture?
8 bytes (64 bits)
Is pointer a normal variable.
Yes in a sense that is also has to be stored at some memory location.
What is int * * name?
A pointer to a pointer which points to data.
How are arguments passed to a function in C?
By value?
Are the any exceptions to call by value?
Yes, arrays. Pointers are also copied by the value they point to can be manipulated directly.
Are int param[] and int * param interchangeable?
YES
What do we use to represent that a pointer points to nothing.
NULL or 0
What will happen if we try to dereference a NULL pointer?
The program will crash.
What is const?
a type qualifier, which indicates the content of the variable cannot be changed. This is enforced by the compiler.
What are the 3 ways that a pointer is unmodifiable.
- pointer itself cannot be changed via float * const ptr;
- the value we are pointing to cannot be changed via const float * ptr;
- both via const float * const ptr;