1

What it the initial values of an array declared in the heap. it's a zero or random values in memory?

int* ptrAr;
ptrAr = new int[5];
4
  • 1
    Related: stackoverflow.com/q/2468203/2602718 Commented May 7, 2019 at 19:37
  • 2
    Random values in memory. Although it can be 0 the first time because your OS probably zero's new pages it gives your application (for security purposes not to leak information from some other application). If you reuse memory from the heap it will contain garbage values from your application. Commented May 7, 2019 at 19:37
  • 2
    Unfortunately none of the "duplicate answer" are pertinent. In the case of dynamic initialization, default initialization does not cause zero initialization. The consequence is that your array hold something much more horrible than a random value: an indeterminate value. Trying to operate on such values causes undefined behavior see c++-standard/[dcl.init] Commented May 7, 2019 at 19:47
  • @πάντα None of the "duplicate answers" sites indeterminate value which what holds the array after this initialization! Which is the answer of this clear question. Commented May 7, 2019 at 19:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.