Thread: I give up on pointers

  1. #16
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    An array is precalculated block of memory that takes up space in the stack. When you are making references to an array you are are using a pointer to that block of memory. i.e. int i[10]; i points to your block of data but is designed only to point to that data whereas a normal pointer can point to arbitrary memory addresses. In other words an array is a pointer, however, it is more restricted (at least it is supposed to be).

    Code:
    int i[10];
    //i is a pointer to a block of memory which is large enough to hold 10 ints.
    //I am trying to carefully word this so that I don't make it sound like I'm saying i is a pointer to an array.
    It is kind of an abstract concept here. But Polymorphic OOP is correct in saying an array isn't a pointer. However in my example shows how a an array is a pointer. I just don't think this subject is debatable.

  2. #17
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    In other words an array is a pointer, however, it is more restricted (at least it is supposed to be).
    No, that is not true at all. In your example "i" is NOT a pointer it is an array, and no, AN ARRAY IS NOT A POINTER!!! It's not a pointer to an array, it's not a pointer to a block of memory, it's not even a pointer to the first element. It's an array period!

    The fact that when you use the array name it represents a pointer means nothing at all! It's the same logic that goes with the return type of a function. A function that returns a pointer to an int is not itself a pointer to an int! The same goes for an array!

    Your example does not show that "i" is a pointer. It only shows that you don't understand what an array is in C++.
    Last edited by Polymorphic OOP; 12-04-2002 at 04:13 AM.

  3. #18
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Back to the original question...

    A pointer is a variable that stores an address of another variable.

    An analogy: Bob doesn't have the homework answers, but he always knows who does. You go to Bob's address and he points to Betty's address one day, and to Sally's address another day.

    I've used a pointer to a class when functions in one class needed to access member functions and member data in another class.

    I was looking at an example program that access the computer hardware a couple of weeks ago. I think they used a pointer to force a variable to "reside" at a particular hardware address... or something like that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. array of pointers to an array pointers
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 07-28-2008, 11:45 AM
  3. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM