CS 3733 Operating Systems, Fall 2006 Assignment 0 Comments
- Explain in your own words what a NULL pointer and a null byte are.
A NULL pointer is a pointer and a null byte is a char.
A null byte has the value 0. A NULL pointer is not of integer type.
If you cast the integer 0 to a pointer, you get a NULL pointer.
If you cast a NULL pointer to an intger the result is system dependent.
- What is the size of each?
The size of the NULL pointer is system dependent,
but is usually 4 or 8 bytes.
The size of a null byte is 1.
- How are they used?
A NULL pointer is used to represent a pointer that does not point to anything.
It is sometimes used as a return value to indicate that an error occurred
and sometimes used for initializing pointers before they have anything to
point to. Often is it used to represent the end of a list of pointers,
possibly a linked list or an array.
- Explain in words why the data type for an array of strings as
described above has data type char **.
A string has data type char * which is a pointer to a char.
An array of these has data type char ** which is a pointer to
a char *.
- Suppose you want to have a function create one of these arrays of pointers
and return it in a parameter, rather than as a return value.
What data type would be passed as this parameter?
Note that there is a difference between a pointer to a pointer to a char
and an array of strings, although they may be represented with the same
data type.