C Programming 06 Flashcards
What is a NULL pointer?
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)
What is meant by a polymorphic pointer?
A pointer of type void* is polymorphic, it can point to any type. You can use this to store an arbitrary pointer.
What is a nested pointer?
A pointer to another pointer.
An int** is just the memory address of an int*
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 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.
What is assert?
assert(x) causes a program to abort if x is false
What is the & bitwise operator?
Binary AND Operator copies a bit to the result if it exists in both operands.
What is the | bitwise operator?
Binary OR Operator copies a bit if it exists in either operand.
What is the ^ bitwise operator?
Binary XOR Operator copies the bit if it is set in one operand but not both.
What is the ~ bitwise operator?
Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.
What is the «_space;bitwise operator?
Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand
What is the»_space; bitwise operator?
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.