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’
What is the ‘~’ operator?
A bitwise one’s complement.
How would you use the bitwise & operator to get the least significant byte from an integer x?
x & 0xff
What operation does the ‘<
An arithmetic left shift.
What operation does the ‘»’ operator perform?
An arithmetic right shift.
What will be the value of i after the following line?
i = 2 «_space;1
4.
An arithmetic left shift by N bits is equivalent to a multiplication by 2^n.
What will be the value of i after the following line?
i = 36»_space; 2
9.
An arithmetic right shift by N bits is equivalent to a division by 2^n.
What does the following line do?
n |= 1 «_space;x
Sets the xth bit of n to 1.
What does the following line do?
n &= ~(1 «_space;x)
Sets the xth bit of n to 0.
What does the following line do?
n ^= 1 «_space;x
Toggles the xth bit of n.