lucproblem016.c (1478B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Figure 9.4 shows three memory locations and values stored in them. 8 Write a program to declare variables that implement the relationship 9 shown. How will you print the values and addresses shown in the figure? 10 On which machine the program should be executed to get such addresses? 11 12 Figure 9.4: 13 value: 3.14, memory_address: 7fff9489c79c 14 value: 7fff9489c7a0, memory_address: 7fff4fd134b8 15 value: 7fff9489c79c, memory_address: 7fff9489c7a0 16 */ 17 /* Let Us C, Chap - 9, Page 160, Problem 9.3 */ 18 19 #include <stdio.h> 20 21 int main() 22 { 23 float a = 3.14; 24 float *c = &a; 25 float **b = &c; 26 27 printf("Location 1 (Variable a):\n"); 28 printf("Value: %g\n", a); 29 printf("Address: %p\n", (void *)&a); 30 printf("------------------------------\n"); 31 32 printf("Location 3 (Variable c: float *):\n"); 33 printf("Value (Address stored): %p\n", (void *)c); 34 printf("Address of c itself: %p\n", (void *)&c); 35 printf("Value pointed to (*c): %g\n", *c); 36 printf("------------------------------\n"); 37 38 printf("Location 2 (Variable b: float **):\n"); 39 printf("Value (Address stored): %p\n", (void *)b); 40 printf("Address of b itself: %p\n", (void *)&b); 41 printf("Value pointed to (*b): %p\n", (void *)*b); 42 printf("Value pointed to (**b): %g\n", **b); 43 printf("------------------------------\n"); 44 45 return 0; 46 }