# Dynamically resizing an Array

**URL:** <https://forum.codewithmosh.com/t/dynamically-resizing-an-array/15073>\
**Category:** C++\
**Created:** [September 11, 2022, 4:51pm UTC](https://forum.codewithmosh.com/t/dynamically-resizing-an-array/15073 "2022-09-11T16:51:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mymacdoescpp](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@mymacdoescpp](https://forum.codewithmosh.com/u/mymacdoescpp)\
**Post date:** [September 11, 2022, 4:51pm UTC](https://forum.codewithmosh.com/t/dynamically-resizing-an-array/15073/1 "2022-09-11T16:51:54Z")

</div>

Hi, I’m learning c/c++ and I dynamically declared an array, I entered more integers than I initialized the array for and I did not resize the array and it still worked!! I initialized the array with 5 elements and entered 10 and I was able to print 10 elements without resizing the array. is that supposed to happen or cLion does that for you? just because if I compile my code on a different system, I don’t want my program to crash!

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [September 11, 2022, 9:15pm UTC](https://forum.codewithmosh.com/t/dynamically-resizing-an-array/15073/2 "2022-09-11T21:15:51Z")

</div>

Could you paste your exact code in a code fence so we know exactly what you mean? Like this:

````auto
```
yourCodeHere = ...;
```

````

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [September 11, 2022, 9:58pm UTC](https://forum.codewithmosh.com/t/dynamically-resizing-an-array/15073/3 "2022-09-11T21:58:47Z")

</div>

For the record: I suspect you are indexing into invalid memory. Doing that will lead to memory corruption in real applications. If that is in fact what you are doing.

Aside: Java would give you an index out of bounds exception, but many (if not all) C languages do not (they just keep indexing to the next memory slot).
