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.
#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;
}
Comments
Leave a comment