Thread: Dynamically create an array?

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by vart View Post
    struct is optional in C++
    Not in all contexts. Assuming "X" is a struct (or class), this is okay:

    Code:
    friend struct X;
    And this isn't:

    Code:
    friend X;

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Difference between what and what else?

    But at a guess, maybe this helps: a declaration like
    Code:
    int a[20];
    is an array declaration, which means that room for 20 integers is set aside and called "a". The name a, by itself, would refer to the start of the array.

    The code
    Code:
    int *b;
    is a pointer declaration, which means that room for a memory address is set aside and called "b". b doesn't point to anywhere in particular, which means that b must not be used until we point it somewhere. We can later, using new, set aside room for some integers, and then assign b to that memory address. Then b[0] will refer to the beginning of that memory, and b[1] will refer to the next "spot", and so on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Dynamically Increasing Array of Integers
    By laserlight in forum C++ Programming
    Replies: 30
    Last Post: 07-04-2008, 07:27 AM
  2. How to init an array dynamically on the heap?
    By karantsch in forum C Programming
    Replies: 6
    Last Post: 01-25-2003, 01:07 AM
  3. Replies: 5
    Last Post: 12-05-2002, 02:27 AM
  4. Create Array size Question
    By popohoma in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 03:04 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM