Results 1 to 8 of 8

Thread: Pointer ^_^

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44

    Pointer ^_^

    Uhhh I got a question..... I never really got the idea of pointers, could some one tell me the real purpose? to save space? ahhhhhhhh.... I mean I know the code and all but I need to know the true concept of it.....
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    In C, to pass something by reference, instead by value. However in C++ we have 'references' to do this.

    But this is not the only use of pointers in C++(Hint: polymorphism).

  3. #3
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    here is a simple, sample of a int pointer in c++6 console.
    Attached Files Attached Files
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    To add, pointers are used in the dynamic memory allocations.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    pointers make life harder for programmers.
    pointers represent indirection, meaning you have a variable storing the memory address of the actual variable, the name says it: they're not the variables themselves, they point to the variable.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    Right, but what is the advantage of knowing and pointing to a variable? Who cares whats the location of the variable? its all FFA84kdhd yada yada yada, what is it good for?
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    nobody actually cares about the addresses, thats why its so bloody stupid and makes life a pain for programmers. In other languages all variables are indirectly referenced anyway, so the actual advantage in C/C++ is that variables don't have to be indirectly referenced, which saves you loads of performance, but when doing anything else pointers are just lowlevel pain.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    heres a classic use. Consider this definition:
    Code:
    template <class sometype>
    struct NODE
    {
         sometype value;
         NODE<sometype> *next;
    };
    
    int main()
    {
         NODE<int> x;
         return 0;
    }
    Now try to compile this

    Code:
    template <class sometype>
    struct NODE
    {
         sometype value;
         NODE<sometype> next;
    };
    
    int main()
    {
         NODE<int> x;
         return 0;
    }
    Last edited by sunburnt; Feb 11th, 2003 at 08:14 PM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width