Answer to Question #199862 in C++ for Skye Jordan

Question #199862

a)   Declare the variable fptr to be a pointer to an object of type float.

b)   Declare the floating point variables num1 and num2.

c)   Assign 100.20 to num1 as initial value.

d)   Assign the address of variable num1 to pointer variable fptr.

e)   Print the value of object pointed to by fptr.

f)    Assign the value of the object pointed to by fptr to variable num2.

g)   Print the value of num2.

h)   Print the address of num1.

i)     Print the address stored in fptr.


1
Expert's answer
2021-05-29T01:58:41-0400
#include <iostream>

using namespace std;

int main()
{
    float *fptr;                       // a) Declare the variable fptr to be a pointer to an object of type float.
    float num1, num2;                  // b) Declare the floating point variables num1 and num2.
    num1 = 100.20;                     // c) Assign 100.20 to num1 as initial value.
    fptr = &num1;                      // d) Assign the address of variable num1 to pointer variable fptr.
    cout << "*fptr=" << *fptr << endl; // e) Print the value of object pointed to by fptr.
    num2 = *fptr;                      // f) Assign the value of the object pointed to by fptr to variable num2.
    cout << "num2=" << num2 << endl;   // g) Print the value of num2.
    cout << "&num1=" << &num1 << endl; // h) Print the address of num1.
    cout << "fptr=" << fptr << endl;   // i) Print the address stored in fptr.
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog