sign the address of the first element in array nums to pointer variable nPtr. // g) Print the value of the array element pointed to by nPtr.

icon
Related questions
Question

Assign the address of the first element in array nums to pointer variable nPtr. // g) Print the value of the array element pointed to by nPtr.

 

Complete the following C++ program by writing statements that perform the tasks indicated in the
code. (1 mark for each task)
#include <iostream>
using namespace std;
int main () {
float numberl =
7.3, number2;
float nums [] = (1.1,2.2,3.3,4.4,5.5};
Il a) Define two variables fPtr and nPtr to be pointer to objects of type float.
// b) Assign the address of variable number1 to pointer variable fPtr.
// c) Assign the value of the object pointed to by fPtr to variable number2.
// d) Print the value of number2 and the value of the object pointed to by fPtr.
Il e) Print the address of number1 and the address stored in fPtr.
// f) Assign the address of the first element in array nums to pointer variable nPtr.
Il g) Print the value of the array element pointed to by nPtr.
// h) Use pointer arithmetic so that nPtr points to the third element of the array.
// i) Print the value of the array element pointed to by nPtr-1;
return 0;
Transcribed Image Text:Complete the following C++ program by writing statements that perform the tasks indicated in the code. (1 mark for each task) #include <iostream> using namespace std; int main () { float numberl = 7.3, number2; float nums [] = (1.1,2.2,3.3,4.4,5.5}; Il a) Define two variables fPtr and nPtr to be pointer to objects of type float. // b) Assign the address of variable number1 to pointer variable fPtr. // c) Assign the value of the object pointed to by fPtr to variable number2. // d) Print the value of number2 and the value of the object pointed to by fPtr. Il e) Print the address of number1 and the address stored in fPtr. // f) Assign the address of the first element in array nums to pointer variable nPtr. Il g) Print the value of the array element pointed to by nPtr. // h) Use pointer arithmetic so that nPtr points to the third element of the array. // i) Print the value of the array element pointed to by nPtr-1; return 0;
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer