Thread: Pointers

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    1

    Pointers

    How do you use a pointer to access an entire array or pass an entire array. I know if u assign a pointer to an array it only represents the first element.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by l_starter_l
    How do you use a pointer to access an entire array or pass an entire array. I know if u assign a pointer to an array it only represents the first element.
    Generally, you do not need to use a pointer to point to an entire array. With a pointer to the first element and the size of the array (or a designated end value like a null character), you can traverse over the whole array. I find that a pointer to an actual array comes in handy usually only when you have a multi-dimensional array.

    On the other hand, if you use the standard containers (or a custom container class, for that matter) you generally do not have to worry about the automatic conversion to pointer types that built-in arrays have.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  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. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM