0

I'm wondering what is initially placed in a dynamically array when first created. It can be an array of anything; int, LinkedList, etc. I'm currently writing code where I initialize an array of 100 LinkedLists, but have not yet populated it.

I'm currently trying to make a HashMap and am creating LinkedLists if they have not yet been created yet.

Jacob Macallan
  • 959
  • 2
  • 8
  • 29
  • you mean declaring a variable without initializing it? – CroCo Nov 18 '15 at 02:10
  • `when first created`, `where I initialize an array` pick one, if you've initialized the array then it will contain whatever you initialized it with. If you haven't, then it depends on different factors such as the syntax used when allocating, whether the class has constructors etc. – user657267 Nov 18 '15 at 02:12
  • No, I mean what exactly is in .... new LinkedLIst[100]. That code there initializes an array of a size capable of holding 100 linkedlists, but what exactly is in each index until I populate it? – Jacob Macallan Nov 18 '15 at 02:12
  • @Xari that depends entirely on the definition of `LinkedLIst`. `That code there initialises` that code there may or may not initialise the array, it depends. – user657267 Nov 18 '15 at 02:12
  • Then what would happen in the case where I do this ... int* nums = new int[100]. What is stored in each index what I initialize the array? This ties to the problem because I want to check if an index is null in order to create the object if it does not yet exist. – Jacob Macallan Nov 18 '15 at 02:15
  • 1
    @Xari That array would be *default-initialized*, which for (automatic arrays of) scalars means, essentially, "garbage", attempting to read those values is undefined behavior. For a user-defined class like `LinkedLIst` this might not be the case if it has a default constructor. – user657267 Nov 18 '15 at 02:16
  • 2
    It will be 100 of whatever would be the default value of 1 `LinkedList`, whatever that is. For primitives, it is garbage data. –  Nov 18 '15 at 02:17
  • 1
    In the duplicate question, check specifically [this answer](http://stackoverflow.com/a/4984228/3425536). – Emil Laine Nov 18 '15 at 02:31

0 Answers0