Question: answer each of the following a a pointer variable contains...
Answer each of the following:
a) A pointer variable contains as its value the________ of another variable.
b) The three values that can be used to initialize a pointer are ____ , ____, and
c) The only integer that can be assigned to a pointer is .
State whether the following are true or false. If the answer is false, explain why.
a) The address operator (&) can be applied only to constants, to expressions and to
variables declared with the storage-class register.
b) A pointer that’s declared to be void can be dereferenced.
c) Pointers of different types may not be assigned to one another without a cast operation.
Answer each of the following. Assume that single-precision floating-point numbers are stored in 16 bytes, and that the starting address of the array is at location 2010500 in memory. Each part of the exercise should use the results of previous parts where appropriate.
a) Define an array of type float called numbers with 5 elements, and initialize the elements to the values 0.11, 0.22, 0.33, ..., 0.55. Assume the symbolic constant SIZE has been defined as 5.
b) Define a pointer, nPtr, that points to an object of type float
c) Print the elements of array numbers using array subscript notation. Use a for
statement and assume the integer control variable i has been defined. Print each
number with 2 position of precision to the right of the decimal point.
d) Give two separate statements that assign the address of last element of array numbers to the pointer variable nPtr.
e) Print the elements of array numbers using pointer/offset
notation with the pointer nPtr.
f) Print the elements of array numbers using pointer/offset notation with the array name as the pointer.
g) Print the elements of array numbers by subscripting pointer nPtr.
h) Refer to element 2 of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr.
i) Assuming that nPtr points to the end of array numbers, what address is referenced
by nPtr - 5? What value is stored at that location?
j) Assuming that nPtr points to numbers, what address is referenced by nPtr – = 2? What’s the value stored at that location?
For each of the following, write a statement that performs the indicated task. Assume that floating-point variables number1 and number2 are defined and that number2 is initialized to 3.1.
a) Define the variable fPtr to be a pointer to an object of type float.
b) Define the variable fPtr2 to be a pointer to a pointer to an object of type float. c) Assign the address of variable number2 to pointer variable fPtr. d) Print the value of the object pointed to by fPtr. e) Assign the value of the object pointed to by fPtr to variable number1.
f) Assign the address of variable fPtr to pointer variable fPtr2.
g) Print the value of number1.
h) Print the address of number2. Use the %p conversion specifier.
i) Print the address stored in fPtr. Use the %p conversion specifier. Is the value printed the same as the address of number2?
j) Print the address stored in fPtr2. Use the %p conversion specifier.
Do each of the following:
a) Write the function header for a function called myswap that takes two pointers to integer numbers x and y as parameters and returns a Boolean value.
b) Write the function prototype for the function in part (a).