Thread: Dynamic array sizing causes crash

  1. #1

    Dynamic array sizing causes crash

    I'm trying to allocate memory to my array but I get a crash.

    int *cellWidth;
    int cols = 50;

    That's a pretty trimmed up version of my source, only the relevant lines out of it.

    Anways I get a crash on XP pro, I gather it's a simple problem I tend to crash my programs with these memory things all the time but never really understood half of them except for the ones that go out of array bounds.

  2. #2
    Registered User
    Join Date
    Dec 2002
    int *cellWidth;
    int cols = 50;
    cellWidth = new int[cols];

    (brackets or parenthesis, i forget, but that hsould be right. unless im missing something)

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    The first is really something in C (though, C++ has it as well), the second C++. I think your crash is elsewhere.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    *smacks head* thanks Zach, I did exactly the same thing with my 2d array I was setting the variable before I had sized it which was causing the crash.

    Cheers to you also revelation!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. beginner: dynamic array of strings
    By pc2-brazil in forum C++ Programming
    Replies: 10
    Last Post: 04-29-2008, 04:29 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. 2D dynamic array problem
    By scsullivan in forum C Programming
    Replies: 3
    Last Post: 12-30-2002, 10:02 PM
  5. Dynamic array allocation and reallocation
    By purple in forum C Programming
    Replies: 13
    Last Post: 08-01-2002, 11:48 AM