Thread: incrementing pointers!?!

  1. #1
    pmit2
    Guest

    Question incrementing pointers!?!

    Could anyone tell me what it means to increment a pointer or array?

    e.g. char* arrayOfStrings[10]; //array of strings, obviously
    //...some code
    arrayOfStrings++ //-- what does this mean??
    //can I increment an array?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Assume

    char *str = "string";

    and

    char *ptr;

    and

    ptr = str;

    then

    ptr++;

    results in ptr pointing to t. An array is a block of memory existing of smaller blocks. In this case, we have a block of memory existing of smaller blocks which are bytes (char). So incrementing the pointer which points to the start of the block, results in the pointer pointing to the next block.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    Code:
    char *str = "string";
    *str is just a char pointer. That means:
    str is the address of the first character of the string.
    *str is the first the value of it (in this case 's').

    You can increment the pointer and then it points at the next value
    (in this case 't').
    if str points to the first character of a string you can write
    *(str+6)
    for
    str[6]
    itīs exactly the same.

    Here is an example for pointer incrementation:
    Code:
    unigned int lenofstring(char *string) /* returns the length of a string */
    {
      char *temp;
    
      temp=string;
    
      while(*string!='\0')
      *string++;
    
      return string-temp;
    }
    klausi
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. incrementing character strings? pointers? HELP!
    By ominub in forum C Programming
    Replies: 10
    Last Post: 05-02-2009, 09:03 PM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Incrementing Pointers Along arrays
    By Red Force in forum C Programming
    Replies: 2
    Last Post: 04-16-2003, 06:45 PM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM