where.c 848 B

1234567891011121314151617181920212223242526272829303132
  1. // where.c -- where's the memory?
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int static_store = 30;
  6. const char * pcg = "String Literal";
  7. int main()
  8. {
  9. int auto_store = 40;
  10. char auto_string[] = "Auto char Array";
  11. int * pi;
  12. char * pcl;
  13. pi = (int *) malloc(sizeof(int));
  14. *pi = 35;
  15. pcl = (char *) malloc(strlen("Dynamic String") + 1);
  16. strcpy(pcl, "Dynamic String");
  17. printf("static_store: %d at %p\n", static_store, &static_store);
  18. printf(" auto_store: %d at %p\n", auto_store, &auto_store);
  19. printf(" *pi: %d at %p\n", *pi, pi);
  20. printf(" %s at %p\n", pcg, pcg);
  21. printf(" %s at %p\n", auto_string, auto_string);
  22. printf(" %s at %p\n", pcl, pcl);
  23. printf(" %s at %p\n", "Quoted String", "Quoted String");
  24. free(pi);
  25. free(pcl);
  26. return 0;
  27. }