06 Flashcards
What should happen when reading or writing to a NULL pointer?
An immediate crash.
Can you cast the NULL pointer to a different type?
Yes
Using arrow notation, what is the equivalent of this line?
(*x).y
x->y
Can pointers be cast from one type to another?
Yes
What sort of data can a void* point to?
Anything. They are used as a pointer of variable type.
Why are void pointers not particularly useful?
They cannot be dereferenced or incremented/decremented.
How many nested pointers can you have? (i.e. a pointer to a pointer to a pointer….)
There is no limit.
What does an int** hold?
The memory address of an integer pointer.
Given the function: int add_numbers(double d, float f) How would you declare a pointer to that function?
int (*ptr) (double, float) = &add_numbers;
How do you declare a pointer to a function?
type (*ptr) (args,…) = function
Where type is the function type, ptr is the name of the pointer and args are the function arguments.
When assert(x) is called, what happens if x is false?
The program aborts and prints an error message.
What happens on underflow/ overflow on unsigned types?
Modulo arithmetic is performed. The values will ‘wrap around’.
What is the ‘&’ operator?
A bitwise ‘and’
What is the ‘|’ operator?
A bitwise ‘inclusive or’
What is the ‘^’ operator?
A bitwise ‘exclusive or’