1. Engineering
  2. Computer Science
  3. answer each of the following a a pointer variable contains...

Question: answer each of the following a a pointer variable contains...

Question details
  1. 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 .

  2. State whether the following are true or false. If the answer is false, explain why.

    1. a) The address operator (&) can be applied only to constants, to expressions and to

      variables declared with the storage-class register.

    2. b) A pointer that’s declared to be void can be dereferenced.

    3. c) Pointers of different types may not be assigned to one another without a cast operation.

  3. 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[5], what address is referenced by nPtr – = 2? What’s the value stored at that location?

  1. 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.

  2. 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.

  3. Do each of the following:

    1. 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.

    2. b) Write the function prototype for the function in part (a).

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution