Thread: simple pointer arithmetic

  1. #1
    Registered User
    Join Date
    Jul 2004

    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:

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

    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?


  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    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, 11:08 PM
  2. Simple pointer question
    By sweets in forum C++ Programming
    Replies: 9
    Last Post: 11-16-2004, 08:48 PM
  3. Pointer arithmetic question
    By moneil in forum C Programming
    Replies: 6
    Last Post: 03-25-2004, 11: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