Practice 7.1 (c- type file)

1 Answer each of the following.Assume that single-precision floating-point numbers are stored in four bytes, and that the array’s starting address is location 1002500 in memory. Each part of the exercise should use the results of previous parts where appropriate.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

a) Define a float array called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, …, 9.9. Assume the symbolic constant SIZE has been defined as 10.b) Define a pointer, nPtr, that points to a float.c) Use a for statement and array subscript notation to print array numbers’ elements. Use one digit of precision to the right of the decimal point.d) Give two separate statements that assign the starting address of array numbers to the pointer variable nPtr. e) Print numbers’ elements using pointer/offset notation with the pointer nPtr.f) Print numbers’ elements using pointer/offset notation with the array name as the pointer.g) Print numbers’ elements by subscripting pointer nPtr.h) Refer to element 4 of 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 beginning of array numbers, what address is referenced by nPtr + 8? What value is stored at that location?j) Assuming that nPtr points to numbers[5], what address is referenced by nPtr –= 4? What’s the value stored at that location?

2 For each of the following, write a statement that performs the specified task.Assume that float variables number1 and number2 are defined and that number1 is initialized to 7.3.a) Define the variable fPtr to be a pointer to an object of type float.b) Assign the address of variable number1 to pointer variable fPtr.c) Print the value of the object pointed to by fPtr.d) Assign the value of the object pointed to by fPtr to variable number2.e) Print the value of number2. f) Print the address of number1. Use the %p conversion specification.g) Print the address stored in fPtr. Use the %p conversion specifier. Is the value printed the same as the address of number1?

3 Do each of the following:a) Write the function header for a function exchange that takes two pointers to floating-point numbers x and y as parameters and does not return a value.b) Write the function prototype for the function in part (a).c) Write the function header for a function evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly, which represents a function that takes an integer parameter and returns an integer. d) Write the function prototype for the function in part (c)

4 Answer each of the following. Assume that integers are stored in four bytes and that the starting address of the array is at location 1002500 in memory.a) Define a five-element int array values, and initialize the elements to the even integers from 2 to 10. Assume the symbolic constant SIZE is defined as 5.b) Define a pointer vPtr that points to an object of type int.c) Print the elements of array values using array subscript notation. Use a for statement and assume integer control variable i has been defined.d) Give two separate statements that assign the starting address of array values to pointer variable vPtr. e) Print the elements of array values using pointer/offset notation.f) Print the elements of array values using pointer/offset notation with the array name as the pointer.g) Print the elements of array values by subscripting the pointer to the array.h) Refer to element 4 of values using array subscript notation, pointer/offset notation via the array name, pointer subscript notation, and pointer/offset notation.i) What address is referenced by vPtr + 3? What value is stored at that location?j) Assuming vPtr points to values[4], what address is referenced by vPtr -= 4? What value is stored at that location?

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

5 For each of the following, write a single statement that performs the indicated task. Assume that long integer variables value1 and value2 have been defined and that value1 has been initialized to 200000.a) Define the variable lPtr to be a pointer to an object of type long.b) Assign the address of variable value1 to pointer variable lPtr.c) Print the value of the object pointed to by lPtr.d) Assign the value of the object pointed to by lPtr to variable value2.e) Print the value of value2. f) Print the address of value1.g) Print the address stored in lPtr. Is the value the same as the address of value1?

6 Do each of the following:a) Write the function header for function zero, which takes a long integer array parameter bigIntegers and does not return a value.b) Write the function prototype for the function in part (a).c) Write the function header for function add1AndSum, which takes an integer array parameter oneTooSmall and returns an integer.d) Write the function prototype for the function described in part (c)

7 Find the error in each of the following program segments and correct the error. Assume:

Still stressed with your coursework?
Get quality coursework help from an expert!