Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. //  Exploring memory
  2. //  Created by Richard Buckland on 2012-11-20.
  3. //
  4. //  Modified by:
  5. //      Your name (your zID)
  6. //      Your partner's name (your partner's zID)
  7. //
  8. //  YYYY-MM-DD
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. long add (int x, int y);
  14.  
  15. int main(int argc, const char * argv[]) {
  16.  
  17.     int x;
  18.     int y;
  19.     long total;
  20.  
  21.     x = 40;
  22.     y = 2;
  23.  
  24.     printf("The size of a int, in bytes, is %u.\n", sizeof(x));
  25.     printf("The variable x is located at memory address %p.\n", &x);
  26.  
  27.     total = add (x, y);
  28.  
  29.     printf("the sum of %d and %d is %ld\n", x, y, total);
  30.  
  31.     char c ='a';
  32.  
  33.     unsigned long ul       = 0;
  34.     unsigned int ui        = 1;
  35.     unsigned long long ull = 2;
  36.     unsigned short us      = 3;
  37.  
  38.     signed long sl       = 4;
  39.     signed int si        = 5;
  40.     signed long long sll = 6;
  41.     signed short ss      = 7;
  42.  
  43.     long l       = 8;
  44.     int i        = 9;
  45.     long long ll = 10;
  46.     short s      = 11;
  47.  
  48.     float f = 3.1;
  49.     double d = 3.14;
  50.  
  51.     // add them all together just to make use of them so the compiler
  52.     // doesn't grumble that they are unused in the program
  53.  
  54.     double grandTotal;
  55.     grandTotal =  c +
  56.         ul + ui + ull + us +
  57.         sl + si + sll + ss +
  58.         l +  i +  ll +  s +
  59.         f + d;
  60.  
  61.     printf ("all these things added together make %f\n",
  62.             grandTotal);
  63.  
  64.     // Add in your own variables, printf statements and arithmetic to
  65.     // figure out the size of different types, where they live
  66.     // and how big the numebrs they store are
  67.  
  68.     return EXIT_SUCCESS;
  69. }
  70.  
  71. long add (int x, int y) {
  72.     long answer;
  73.     answer = x + y;
  74.  
  75.     return answer;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement