Question

In: Computer Science

Answer each of the following. Assume that single-precision floating-point numbers are stored in 8 bytes, and...

Answer each of the following. Assume that single-precision floating-point numbers are stored in 8 bytes, and that the starting address of the array is at location 2030100 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 typefloat.

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) Printthe 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 pointsto the end of array numbers (i.e., the memory location after the last element of the array), what addressisreferenced by nPtr - 5? What value is stored at thatlocation? j) Assuming that nPtr points to numbers[5], what address is referenced by nPtr – = 2? What’s the value stored at that location?

Solutions

Expert Solution

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.
Answer:-----
float
numbers[ SIZE ] ={ 0.11, 0.22, 0.33, 0.44, 0.55 };

b) Define a pointer, nPtr, that points to an object of typefloat.
Answer:-----
float *nPtr;

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.
Answer:-----
for
( i = 0; i < SIZE; ++i )
printf( "%.2f ", numbers[ i ] );

d) Give two separate statements that assign the address of last element of array numbers to the pointer variable nPtr.
Answer:------
nPtr = numbers;
nPtr = &numbers[ SIZE ];

e) Print the elements of array numbers using pointer/offset notation with the pointer nPtr.
Answer:------
for ( i = 0; i < SIZE; ++i )
printf( "%.1f ", *( nPtr + i ) );

f) Print the elements of array numbers using pointer/offset notation with the array name as the pointer.
Answer:------
for ( i = 0; i < SIZE; ++i )
printf( "%.1f ", *( numbers + i ) );

g) Print the elements of array numbers by subscripting pointer nPtr.
Answer:------
for( i = 0; i < SIZE; ++i )
printf( "%.1f ", nPtr[ i ] );

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.
Answer:------
numbers[ 2 ]
*( numbers + 2)

nPtr[ 2]
*( nPtr + 2)

i) Assuming that nPtr points to the end of array numbers (i.e., the memory location after the last element of the array), what address is referenced by nPtr - 5? What value is stored at that location?
Answer:------
The address is 2030100 - 5 * 8 = 2030060.
No value.

j) Assuming that nPtr points to numbers[5], what address is referenced by nPtr – = 2? What’s the value stored at that location?
Answer:------
The address of numbers[ 5 ] is 2030100 + 5*8 = 2030140.
The address of nPtr -= 2 is 2030140 - 2*8 = 2030124
The value at that location is 0.44.


Related Solutions

Given the following 32-bit binary sequences representing single precision IEEE 754 floating point numbers: a =...
Given the following 32-bit binary sequences representing single precision IEEE 754 floating point numbers: a = 0100 0000 1101 1000 0000 0000 0000 0000 b = 1011 1110 1110 0000 0000 0000 0000 0000 Perform the following arithmetic and show the results in both normalized binary format and IEEE 754 single-precision format. Show your steps. a)     a + b b)     a × b
Express the following two base 10 numbers in binary using the IEEE 754 single-precision floating point...
Express the following two base 10 numbers in binary using the IEEE 754 single-precision floating point format (i.e., 32 bits). Express your final answer in hexadecimal (e.g., 32’h????????). a) 68.3125 b) -19.675
Using IEEE 754 single precision floating point, write the hexadecimal representation for each of the following:...
Using IEEE 754 single precision floating point, write the hexadecimal representation for each of the following: a. Zero b. -2.0 (base 10) c. 256. 0078125 (base 10) d. Negative infinity
6a) (6 pts. each) Find the decimal represented by the 32-bit single precision floating point number...
6a) (6 pts. each) Find the decimal represented by the 32-bit single precision floating point number for the hexadecimal value C47CD000.
Represent the following numbers in IEEE half-precision floating point. Indicate problems where you run into them....
Represent the following numbers in IEEE half-precision floating point. Indicate problems where you run into them. 1 -10 55595472 -π (PI) The speed of light in meters per second
Determine the IEEE single and double floating point representation of the following numbers: a) -26.25 b)...
Determine the IEEE single and double floating point representation of the following numbers: a) -26.25 b) 15/2
Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in...
Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in non-standard form. 0100_0001_1110_0010_1000_0000_0000_0000
2. a) Represent the decimal value 47.375 as a single precision IEEE floating point number. Give...
2. a) Represent the decimal value 47.375 as a single precision IEEE floating point number. Give your answer in hexadecimal and show your work. b) Represent the decimal value 47.375 as a double precision IEEE floating point number. Give your answer in hexadecimal and show your work.
For IEEE 754 single-precision floating point, what is the hexadecimal representation of 27.101562? A. 35CCD001 B....
For IEEE 754 single-precision floating point, what is the hexadecimal representation of 27.101562? A. 35CCD001 B. 2F5C10D0 C. 41D8D000 D. 7DCA1111 E. None of the above
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT