Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* Here you can write everything in a main() function. Suppose fred is a double

ID: 3563009 • Letter: #

Question

/*
Here you can write everything in a main() function. Suppose fred is a double variable. Assign fred a value.
Display the value of fred. Declare a pointer that points to fred. Display the value of fred using this pointer.
Display the address of fred in decimal and hexadecimal format, with and without pointer use. Change the
value of fred by using the pointer. Display the value of fred with and without pointer use.
*/
#include <stdio.h>

int main ()
{
  
double fred = 42.24; /* actual variable declaration */
double *fredsPointer; /* pointer variable declaration */

fredsPointer = &fred; /* store address of fred in pointer variable */
  
printf(" -------Welcome------- -------Program------- ----------1---------- - Hello my name is fred my value is: %.4g - ", fred);

/* access the value using the pointer, after dereferencing the pointer */
printf("Value of fred using *fredsPointer: %.4g - ", *fredsPointer);

/* freds address in decimal*/
printf("fred's address in decimal is: HELP HERE ");

/* freds address in hexadecimal */
printf("fred's address in hexadecimal is: %p - ", &fred);
  
/* The address of fred using fredsPointer in decimal and hexadecimal */

printf("fred's address using fredsPointer in decimal is: AND HERE", );

printf("fred's address using fredsPointers in hexadecimal is: %p - ", fredsPointer);

/* changing fred's value */
printf("Adding 57.76 to fred using fredsPointer ");
*fredsPointer +=57.76;

/* access the value using the pointer and directly*/
printf("Value of fred using pointer: %.4g Value of fred: %.4g -", *fredsPointer, fred );

printf(" --------Good--------- --------Bye---------- ");


return 0;
}

Explanation / Answer

/*
Here you can write everything in a main() function. Suppose fred is a double variable. Assign fred a value.
Display the value of fred. Declare a pointer that points to fred. Display the value of fred using this pointer.
Display the address of fred in decimal and hexadecimal format, with and without pointer use. Change the
value of fred by using the pointer. Display the value of fred with and without pointer use.
*/
#include <stdio.h>

int main()
{

   double fred = 42.24; /* actual variable declaration */
   double *fredsPointer; /* pointer variable declaration */

   fredsPointer = &fred; /* store address of fred in pointer variable */

   printf(" -------Welcome------- -------Program------- ----------1---------- - Hello my name is fred my value is: %.4g - ", fred);

   /* access the value using the pointer, after dereferencing the pointer */
   printf("Value of fred using *fredsPointer: %.4g - ", *fredsPointer);

   /* freds address in decimal (%u is used to print unsigned decimal, we can also use %d)*/
   printf("fred's address in decimal is: %u ", fredsPointer);

   /* freds address in hexadecimal */
   printf("fred's address in hexadecimal is: %p - ", &fred);

   /* The address of fred using fredsPointer in decimal and hexadecimal */

   printf("fred's address using fredsPointer in decimal is: %u ", fredsPointer);

   printf("fred's address using fredsPointers in hexadecimal is: %p - ", fredsPointer);

   /* changing fred's value */
   printf("Adding 57.76 to fred using fredsPointer ");
   *fredsPointer += 57.76;

   /* access the value using the pointer and directly*/
   printf("Value of fred using pointer: %.4g Value of fred: %.4g -", *fredsPointer, fred);

   printf(" --------Good--------- --------Bye---------- ");


   return 0;
}