Implement a C program that declares and initializes to any v

Implement a C program that declares and initializes (to any value you like) a double, an int, and a char. Next declare and initialize a pointer to each of the three variables. Your program should then print the address of, and value stored in, and the memory size (in bytes) of each of the six variables.
Make use of the “0x%x” formatting specifier to print addresses in hexadecimal. You should see addresses that look something like this: \"0xbfe55918\". The initial characters \"0x\" tell you that hexadecimal notation is being used; the remainder of the digits give the address itself.
The sizeof operator should be used to determine the memory size allocated for each variable.

Solution

#include <stdio.h>

int main(){
   double d = 4.8;
   int i = 22;
   char c = \'k\';
   double *dp = &d;
   int *ip = &i;
   char *cp = &c;
   printf(\"Address: 0x%p, value: %lf, Size: %lu\ \", &d, d, sizeof(d));
   printf(\"Address: 0x%p, value: %d, Size: %lu\ \", &i, i, sizeof(i));
   printf(\"Address: 0x%p, value: %c, Size: %lu\ \", &c, c, sizeof(c));

   printf(\"Address: 0x%p, value: %p, Size: %lu\ \", &dp, dp, sizeof(dp));
   printf(\"Address: 0x%p, value: %p, Size: %lu\ \", &ip, ip, sizeof(ip));
   printf(\"Address: 0x%p, value: %p, Size: %lu\ \", &cp, cp, sizeof(cp));
}

Implement a C program that declares and initializes (to any value you like) a double, an int, and a char. Next declare and initialize a pointer to each of the t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site