Memory to pointers

This is a discussion on Memory to pointers within the C++ Programming forums, part of the General Programming Boards category; When you declare a pointer what is the difference in doing structure *s = new structure; delete s; vs. structure ...

  1. #1
    Unregistered
    Guest

    Memory to pointers

    When you declare a pointer what is the difference in doing
    structure *s = new structure;
    delete s;

    vs.

    structure *s;

    I don't understand what the new and delete thing does. Thanks everybody.

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    In your first example 's' is a variable that holds the address of a 'structure'. 's' points to an instance of 'structure' created on the heap, it contains it's address .

    In your second example 's' is a variable that holds the address of a 'structure'. It points to nothing, and doesn't contain a valid address of a 'structure' and so cannot be used to access one.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and dynamic memory
    By tkansara in forum C Programming
    Replies: 1
    Last Post: 06-16-2009, 09:22 AM
  2. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  3. Replies: 2
    Last Post: 11-28-2003, 10:50 AM
  4. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  5. pointers and memory
    By itld in forum C++ Programming
    Replies: 4
    Last Post: 02-06-2002, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21