Results 1 to 5 of 5

Thread: how do i declare and delete pointers??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Cool how do i declare and delete pointers??

    ?

  2. #2
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    there..

    If you want simple pointers, on the stack, you declare themlike this:
    Code:
    int a; //an integer
    int *pInt; //a pointer to an integer...
    //you could have initialized it on the previous line, but you can also do it like this
    pInt = &a;
    now if you want a pointer on the heap space, you do it like this:
    Code:
    int *pInt = new int; //that creates a pointer to an integer on the heap. Initialize it like above
    int a;
    pInt = &a; //now pInt points to a;
    I hope that helps...=)
    Amon Ra
    The Power of Learning.

  3. #3
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Talking

    ok, i forgot to say how to delete a pointer on heap
    Code:
    int a;
    int *pInt = new int;
    pInt = &a;
    //now to free the memory
    delete pInt;//deletes the pointer on the heap..
    Amon Ra
    The Power of Learning.

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    If you talk about create/delete a pointer point to a string then..

    PHP Code:
    //Create a pointer point to a string with size of 10
    char *MyStr = new char[10];
    //Reset the content
    memset(MyStr010);

    //. Put your code here...

    //Delete the pointer
    delete [] MyStr

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Cool thnx allot


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