delete []

This is a discussion on delete [] within the C++ Programming forums, part of the General Programming Boards category; Will an error ocure if I use delete [] var and the var pointer isn't pointing at anything. This could ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    160

    delete []

    Will an error ocure if I use delete [] var and the var pointer isn't pointing at anything. This could happen if you have an if statement and only if this is correct var will be set to point at whatever. But if it's not correct then it wont point at **** and you will delete an adress that doesn't exist. Is this a problem.
    If it is I'll move the delete [] into the end of the if statement.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    As far as I know, you can call delete/delete[] on a NULL pointer without problems, but if you call it on a memory address that doesnt hold memory allocated by new/new[] then the outcome is undefined....most likely it will crash

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    I think it will delete whats at that given addres and then if you have to use that variable you're... YES!
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help on understandind arrays
    By C++mastawannabe in forum C++ Programming
    Replies: 9
    Last Post: 06-16-2007, 11:50 PM
  2. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 02:52 PM
  3. Which comes first...delete [] or NULL?
    By Waldo2k2 in forum C++ Programming
    Replies: 13
    Last Post: 08-09-2002, 10:05 AM
  4. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 01:45 PM
  5. memory management...
    By master5001 in forum Game Programming
    Replies: 24
    Last Post: 01-07-2002, 05:50 PM

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