C Programming 06 Flashcards

1
Q

What is a NULL pointer?

A

NULL is a generic pointer value which can be used to denote “doesn’t point anywhere”
• Usually written as (void)0
• Can cast to other pointer types (i.e (int
)NULL)

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

What is meant by a polymorphic pointer?

A

A pointer of type void* is polymorphic, it can point to any type. You can use this to store an arbitrary pointer.

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

What is a nested pointer?

A

A pointer to another pointer.

An int** is just the memory address of an int*

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

Past Paper Question: Describe the concept of using a pointer to a pointer, such as int **m, to represent a 2-D array (for example a matrix with N rows and M columns). Include in your description an explanation of when this representation would be used in preference to arrays and how to read and write elements of the matrix.

A

A 2D array is viewed as an array of 1D arrays. That is, each row in a 2D array is a 1D array. Dereferencing m would then get the first row, and using pointer arithmetic you could access any row. Using pointers you can pass the arrays by reference, and can dynamically allocate memory.

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

What is assert?

A

assert(x) causes a program to abort if x is false

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

What is the & bitwise operator?

A

Binary AND Operator copies a bit to the result if it exists in both operands.

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

What is the | bitwise operator?

A

Binary OR Operator copies a bit if it exists in either operand.

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

What is the ^ bitwise operator?

A

Binary XOR Operator copies the bit if it is set in one operand but not both.

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

What is the ~ bitwise operator?

A

Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.

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

What is the &laquo_space;bitwise operator?

A

Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand

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

What is the&raquo_space; bitwise operator?

A

Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.

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