simple pointer arithmetic

This is a discussion on simple pointer arithmetic within the C Programming forums, part of the General Programming Boards category; I have a question regarding pointers. Let's say I pass a character array through a function parameter as a constant ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    simple pointer arithmetic

    I have a question regarding pointers. Let's say I pass a character array through a function parameter as a constant pointer as such:


    Code:
    void main(void)
    {
          char disk[10];
          // some code until
          usart_str_write(disk);
    
          // some more code
    }
    
    void usart_str_write(const char* string)
    {
         while (*string != "\0")
         {
               Usart_Write(*string);
               string++;
         }
    }
    given function declaration

    Code:
    char Usart_Write(char data);
    In usart_str_write, should I do anything to make the pointer *string derefence back to the initial character, although I won't be doing any more tasks with it?

    Thanks.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,300
    It's perfectly fine to leave the pointer pointing to absolutely anything you like when exiting the function as the pointer goes out of scope and then will simply cease to exist.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. understanding pointer arithmetic
    By firstofthegreat in forum C Programming
    Replies: 3
    Last Post: 02-28-2008, 10:08 PM
  2. Simple pointer question
    By sweets in forum C++ Programming
    Replies: 9
    Last Post: 11-16-2004, 07:48 PM
  3. Pointer arithmetic question
    By moneil in forum C Programming
    Replies: 6
    Last Post: 03-25-2004, 10:45 PM
  4. Pointer arithmetic
    By freebu in forum C Programming
    Replies: 4
    Last Post: 04-27-2003, 09:27 AM
  5. pointer arithmetic with characters
    By VanJay011379 in forum C++ Programming
    Replies: 6
    Last Post: 07-21-2002, 01:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21