06 Flashcards

1
Q

What should happen when reading or writing to a NULL pointer?

A

An immediate crash.

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

Can you cast the NULL pointer to a different type?

A

Yes

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

Using arrow notation, what is the equivalent of this line?

(*x).y

A

x->y

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

Can pointers be cast from one type to another?

A

Yes

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

What sort of data can a void* point to?

A

Anything. They are used as a pointer of variable type.

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

Why are void pointers not particularly useful?

A

They cannot be dereferenced or incremented/decremented.

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

How many nested pointers can you have? (i.e. a pointer to a pointer to a pointer….)

A

There is no limit.

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

What does an int** hold?

A

The memory address of an integer pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Given the function:
int add_numbers(double d, float f)
How would you declare a pointer to that function?
A

int (*ptr) (double, float) = &add_numbers;

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

How do you declare a pointer to a function?

A

type (*ptr) (args,…) = function

Where type is the function type, ptr is the name of the pointer and args are the function arguments.

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

When assert(x) is called, what happens if x is false?

A

The program aborts and prints an error message.

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

What happens on underflow/ overflow on unsigned types?

A

Modulo arithmetic is performed. The values will ‘wrap around’.

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

What is the ‘&’ operator?

A

A bitwise ‘and’

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

What is the ‘|’ operator?

A

A bitwise ‘inclusive or’

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

What is the ‘^’ operator?

A

A bitwise ‘exclusive or’

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

What is the ‘~’ operator?

A

A bitwise one’s complement.

17
Q

How would you use the bitwise & operator to get the least significant byte from an integer x?

A

x & 0xff

18
Q

What operation does the ‘<

A

An arithmetic left shift.

19
Q

What operation does the ‘»’ operator perform?

A

An arithmetic right shift.

20
Q

What will be the value of i after the following line?

i = 2 &laquo_space;1

A

4.

An arithmetic left shift by N bits is equivalent to a multiplication by 2^n.

21
Q

What will be the value of i after the following line?

i = 36&raquo_space; 2

A

9.

An arithmetic right shift by N bits is equivalent to a division by 2^n.

22
Q

What does the following line do?

n |= 1 &laquo_space;x

A

Sets the xth bit of n to 1.

23
Q

What does the following line do?

n &= ~(1 &laquo_space;x)

A

Sets the xth bit of n to 0.

24
Q

What does the following line do?

n ^= 1 &laquo_space;x

A

Toggles the xth bit of n.

25
Q

What does the following line do?

n & (1 &laquo_space;x)

A

Checks the xth bit of n.

If it was 0, then n will now equal 0. Otherwise, n will be greater than 0.