dmilicev

play_with_pointers_v1.c

Oct 5th, 2020 (edited)
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     play_with_pointers_v1.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 *str = "GATEEXAM";
  21.  
  22.     printf("\n str = %s \n\n", str );
  23.     printf("\n ---------------------- \n");
  24.  
  25.     printf("\n *((str--)   )  )   = %c \n", *((str--    )  )  ); // G
  26.     str++;  // because we had str--
  27.     printf("\n *((str-- + 2)  )   = %c \n", *((str-- + 2)  )  ); // T
  28.     str++;  // because we had str--
  29.     printf("\n *((str-- + 2)+1)   = %c \n", *((str-- + 2)+1)  ); // E
  30.     str++;  // because we had str--
  31.     printf("\n *((str-- + 2)+1)-3 = %c \n", *((str-- + 2)+1)-3); // B because E-3=B in ASCII table
  32.     str++;  // because we had str--
  33.  
  34.     printf("\n ---------------------- \n");
  35.  
  36.     printf("\n *(--str  )    = %c \n", *(--str  )    ); // something in memory, left from G, undefined
  37.     str++;  // because we had str--
  38.     printf("\n *(--str+3)    = %c \n", *(--str+3)    );  // T
  39.     str++;  // because we had str--
  40.     printf("\n *(--str+3)+32 = %c \n", *(--str+3)+32 );  // t because T+32=t in ASCII table
  41.     str++;  // because we had str--
  42.  
  43.     printf("\n ---------------------- \n");
  44.  
  45.     printf("\n *(++str  )   = %c \n", *(++str  )   );  // A
  46.     --str;  // because we had ++str
  47.     printf("\n *(++str+2)   = %c \n", *(++str+2)   );  // E
  48.     --str;  // because we had ++str
  49.     printf("\n *(++str+2)+4 = %c \n", *(++str+2)+4 );  // I because E+4=I in ASCII table
  50.     --str;  // because we had ++str
  51.  
  52.     printf("\n ---------------------- \n");
  53.  
  54.  
  55.     return 0;
  56. }
  57.  
RAW Paste Data Copied