Thread: meaning!!

  1. #1
    Unregistered
    Guest

    meaning!!

    What is the meaning of:

    char t[20];
    char *pt;
    pt=t;

    ...
    for (pt=pt+(strlen(t)-1);pt>=t;pt--)
    ...



    These are pointers what is this line of code saying??...in plain english please!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) char t[20];

    Declare an array of characters, 20 characters in length, named 't'.

    2) char *pt;

    Declare a pointer to a character, and call it 'pt'.

    3) pt=t;

    Make 'pt' point to the array 't'. Recall that you can use the name of an array as a pointer to the first element in the array.

    3) for(

    Begin looping.

    4) pt=pt+(strlen(t)-1);

    Make 'pt' point to the end of the string. We do this by getting the length of the string, by using 'strlen', and subtracting one.

    If we didn't subtract one, we'd end up pointing past the string. Much like when you index an array, you subtract one.

    5) pt>=t;

    As I mentioned before, you can use the name of an array as a pointer to the first element of the array. What we're doing here is saying, "loop until our pointer is pointing back before the first element in the array.

    6) pt--)

    Decrement the pointer so that it points to the space in memory one place before it's current location.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Unregistered
    Guest

    Wink

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is the meaning of "offset"
    By cromologic in forum C Programming
    Replies: 5
    Last Post: 05-02-2008, 09:09 AM
  2. the meaning of " >> "
    By arian in forum C++ Programming
    Replies: 8
    Last Post: 03-30-2005, 10:40 AM
  3. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  4. would you help me with Linked list, please?
    By unhwan in forum C Programming
    Replies: 1
    Last Post: 06-11-2002, 12:24 AM
  5. WINAPI: Meaning of HDC ?
    By Mecnels in forum Windows Programming
    Replies: 1
    Last Post: 01-21-2002, 10:06 AM