bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / letusc / lucproblem016.c

lucproblem016.c (1342B)


      1 /* Figure 9.4 shows three memory locations and values stored in them.
      2 Write a program to declare  variables that implement the relationship
      3 shown. How will you print the values and addresses shown in the figure?
      4 On which machine the program should be executed to get such addresses?
      5 
      6 Figure 9.4:
      7     value: 3.14, memory_address: 7fff9489c79c
      8     value: 7fff9489c7a0, memory_address: 7fff4fd134b8
      9     value: 7fff9489c79c,  memory_address: 7fff9489c7a0
     10 */
     11 /* Let Us C, Chap - 9, Page 160, Problem 9.3 */
     12 
     13 #include <stdio.h>
     14 
     15 int main()
     16 {
     17     float a = 3.14;
     18     float *c = &a;
     19     float **b = &c;
     20 
     21     printf("Location 1 (Variable a):\n");
     22     printf("Value: %g\n", a);
     23     printf("Address: %p\n", (void *)&a);
     24     printf("------------------------------\n");
     25 
     26     printf("Location 3 (Variable c: float *):\n");
     27     printf("Value (Address stored): %p\n", (void *)c);
     28     printf("Address of c itself: %p\n", (void *)&c);
     29     printf("Value pointed to (*c): %g\n", *c);
     30     printf("------------------------------\n");
     31 
     32     printf("Location 2 (Variable b: float **):\n");
     33     printf("Value (Address stored): %p\n", (void *)b);
     34     printf("Address of b itself: %p\n", (void *)&b);
     35     printf("Value pointed to (*b): %p\n", (void *)*b);
     36     printf("Value pointed to (**b): %g\n", **b);
     37     printf("------------------------------\n");
     38 
     39     return 0;
     40 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror