dmilicev

play_with_pointers_v2.c

Oct 5th, 2020
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     play_with_pointers_v2.c
  4.  
  5.     Useful link for ASCII table
  6.     http://www.asciitable.com/
  7.  
  8.  
  9.     You can find all my C programs at Dragan Milicev's pastebin:
  10.  
  11.     https://pastebin.com/u/dmilicev
  12.  
  13. */
  14.  
  15.  
  16. #include <stdio.h>
  17.  
  18. int main()
  19. {
  20.     char *str1 = "ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxzy";
  21.     char *str = str1 + 26;
  22.  
  23.     printf("\n str1 = %s \n", str1 );
  24.     printf("\n                            str = %s \n", str );
  25.     printf("\n ---------------------- \n");
  26.  
  27.     printf("\n *((str--)   )  )   = %c \n", *((str--    )  )  ); // a
  28.     str++;  // because we had str--
  29.     printf("\n *((str-- + 2)  )   = %c \n", *((str-- + 2)  )  ); // c
  30.     str++;  // because we had str--
  31.     printf("\n *((str-- + 2)+1)   = %c \n", *((str-- + 2)+1)  ); // d
  32.     str++;  // because we had str--
  33.     printf("\n *((str-- + 2)+1)-3 = %c \n", *((str-- + 2)+1)-3); // a because d-3=a in ASCII table
  34.     str++;  // because we had str--
  35.  
  36.     printf("\n ---------------------- \n");
  37.  
  38.     printf("\n *(--str  )    = %c \n", *(--str  )    ); // Y
  39.     str++;  // because we had str--
  40.     printf("\n *(--str+3)    = %c \n", *(--str+3)    ); // c
  41.     str++;  // because we had str--
  42.     printf("\n *(--str+3)+32 = %c \n", *(--str+3)+32 ); // â something in memory right from c, c+32 = ???
  43.     str++;  // because we had str--
  44.  
  45.     printf("\n ---------------------- \n");
  46.  
  47.     printf("\n *(++str  )   = %c \n", *(++str  )   );  // b
  48.     --str;  // because we had ++str
  49.     printf("\n *(++str+2)   = %c \n", *(++str+2)   );  // d
  50.     --str;  // because we had ++str
  51.     printf("\n *(++str+2)+4 = %c \n", *(++str+2)+4 );  // h because d+4=h in ASCII table
  52.     --str;  // because we had ++str
  53.  
  54.     printf("\n ---------------------- \n");
  55.  
  56.  
  57.     return 0;
  58. }
  59.  
RAW Paste Data Copied