Advertisement
thenewboston

C Programming Tutorial - 44 - Arrays and Pointers

Aug 22nd, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9.     int i;
  10.     int meatBalls[5] = {7,9,43,21,3};
  11.  
  12.     printf("Element \t Address \t Value \n");
  13.  
  14.     for(i=0; i<5; i++){
  15.         printf("meatBalls[%d] \t %p \t %d \n", i, &meatBalls[i], meatBalls[i]);
  16.     }
  17.  
  18.     //array names are just pointers to the first element
  19.     printf("\nmeatBalls \t\t %p \n", meatBalls);
  20.  
  21.     //dereference it
  22.     printf("*meatBalls \t\t %d \n", *meatBalls);
  23.     printf("*(meatBalls+2) \t\t %d \n", *(meatBalls+2) );
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement