Consider the following declaration. For each of the following statements (a) to (f) write a
single statement to perform the indicated task.
float number1 = 7.3, number2;
(a) Declare 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 together with a suitable message.
(d) Assign the value of the object pointed to by fPtr to the variable number2.
(e) Print the address of number1 together with a suitable message.
(f) Print the value stored in fPtr together with e suitable message
#include <stdio.h>
int main() {
float number1, number2;
float *fPtr;
number1 = 7.3;
fPtr = &number1;
printf("Value of the object pointed to by fPtr: %f\n", *fPtr);
printf("Address of the object pointed to by fPtr: %p\n", fPtr);
number2 = *fPtr;
printf("number2 = %f\n", number2);
printf("Address of number1 = %p\n", &number1);
printf("Value stored in fPtr: %f\n", *fPtr);
}
Comments
Leave a comment