array problem

This is a discussion on array problem within the C++ Programming forums, part of the General Programming Boards category; I have a array which stores integer. Is there a way to delete all the elements of the array in ...

  1. #1
    Unregistered
    Guest

    Question array problem

    I have a array which stores integer. Is there a way to delete all the elements of the array in the program itselft. I am not using new to create an array.
    But I want all the contents of the array to be deleted .
    How do I do that?

  2. #2
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    myarray = {0};
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    21
    As fart as I know, there isn't a way to do that because the memory for this array is located at compile time if you do not use dynamic allocation with new.

    But you can flag the elements indicating that there are not further used, for example you can set the array pointer to null.
    Code:
    int main()
    {
    int somearray[somesize];
    //Use array
    //flag array as unusable
    somearray[0] = NULL;
    return 0;
    }

  4. #4
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Oh... he meant deleting all the dimensions.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Replies: 6
    Last Post: 02-15-2005, 10:20 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM

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