RicardasSim

pointers

Aug 14th, 2019
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. int main()
  8. {
  9.     char arr[10] = {'a','b','c','d','e','f','g','h','i','j'};
  10.  
  11.     char *p = &arr[10];
  12.  
  13.  
  14.     printf("%c\n",p[-1]);
  15.  
  16.     printf("%c\n",(-1)[p]);
  17.  
  18.    
  19.     printf("%c\n",(-1)[&arr[10]]);
  20.  
  21.     printf("%c\n",(-1)[arr+10]);
  22.  
  23.  
  24.     printf("%c\n",*(&2[arr]));
  25.  
  26.     printf("%c\n",*(arr+2));
  27.  
  28.     printf("%c\n",2[arr]);
  29.  
  30.     printf("%c\n",arr[2]);
  31.  
  32.  
  33.     return 0;
  34. }
  35.  
  36. /*
  37. output:
  38.  
  39. j
  40. j
  41. j
  42. j
  43. c
  44. c
  45. c
  46. c
  47.  
  48. */
Advertisement
Add Comment
Please, Sign In to add comment