allocate no space for dynamic array~

This is a discussion on allocate no space for dynamic array~ within the C++ Programming forums, part of the General Programming Boards category; hi all~ we can build dynamic array just like this: Code: int num = 10; int* arr = new int[num]; ...

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    allocate no space for dynamic array~

    hi all~

    we can build dynamic array just like this:
    Code:
    int num = 10;
    int* arr = new int[num];
    and i wonder what if num = 0 ? does arr really holds memory allocated or not ?
    Never end on learning~

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Try it for yourself to see what happens.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >and i wonder what if num = 0 ?
    You get a pointer to an array of size 0. The pointer is valid, but you can't dereference it.

    >does arr really holds memory allocated or not ?
    No, it "points to" memory allocated.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 12:30 PM
  3. when to allocate memory
    By SAMSAM in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2003, 10:40 PM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM

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