Advertisement
rfmonk

mem_segments.c

Jan 3rd, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char globeBuf[65536];       // Unitialized data segment
  5. int primes[] = {2, 3, 5, 7};// Initialized data segment
  6.  
  7. static int
  8. square(int x)               // Allocated in frame for square()
  9. {
  10.     int result;             // Allocated in frame for square()
  11.  
  12.     result = x * x;
  13.     return result;          // Return value passed via register
  14.  
  15. }
  16.  
  17. static void
  18. doCalc(int val)             // Allocated in frame for doCalc()
  19. {
  20.     printf("The square of %d is %d\n", val, square(val));
  21.  
  22.     if (val < 1000) {
  23.         int t;              // Allocated in frame for doCalc()
  24.        
  25.         t = val * val * val;
  26.         printf("The cube of %d is %d\n", val, t);
  27.     }
  28. }
  29.  
  30. int
  31. main(int argc, char *argv[])// Allocated in frame for main()
  32. {
  33.     static int key = 9973;  // Initialized data segment
  34.     static char mbuf[10240000]; // Uninitialized data segment
  35.     char *p;
  36.  
  37.     p = malloc(1024);       // Points to memory in heap segment
  38.  
  39.     doCalc(key);
  40.  
  41.     exit(EXIT_SUCCESS);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement