Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- play_with_pointers_v1.c
- Useful link for ASCII table
- http://www.asciitable.com/
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main()
- {
- char *str = "GATEEXAM";
- printf("\n str = %s \n\n", str );
- printf("\n ---------------------- \n");
- printf("\n *((str--) ) ) = %c \n", *((str-- ) ) ); // G
- str++; // because we had str--
- printf("\n *((str-- + 2) ) = %c \n", *((str-- + 2) ) ); // T
- str++; // because we had str--
- printf("\n *((str-- + 2)+1) = %c \n", *((str-- + 2)+1) ); // E
- str++; // because we had str--
- printf("\n *((str-- + 2)+1)-3 = %c \n", *((str-- + 2)+1)-3); // B because E-3=B in ASCII table
- str++; // because we had str--
- printf("\n ---------------------- \n");
- printf("\n *(--str ) = %c \n", *(--str ) ); // something in memory, left from G, undefined
- str++; // because we had str--
- printf("\n *(--str+3) = %c \n", *(--str+3) ); // T
- str++; // because we had str--
- printf("\n *(--str+3)+32 = %c \n", *(--str+3)+32 ); // t because T+32=t in ASCII table
- str++; // because we had str--
- printf("\n ---------------------- \n");
- printf("\n *(++str ) = %c \n", *(++str ) ); // A
- --str; // because we had ++str
- printf("\n *(++str+2) = %c \n", *(++str+2) ); // E
- --str; // because we had ++str
- printf("\n *(++str+2)+4 = %c \n", *(++str+2)+4 ); // I because E+4=I in ASCII table
- --str; // because we had ++str
- printf("\n ---------------------- \n");
- return 0;
- }
Add Comment
Please, Sign In to add comment