Question: Looks like a very dumb question:
Here is how an array pointer is declared:

```
double * y = new double[26];

```

After this declaration, I watched y when the program was running, and here is what I have seen:

```
name    value
y[224] 8.691694942331e-310#DEN
y[225] CXX0030: Error: Expression cannot be evaluated

```

So I am wondering why a double array declared with 26 length has 224 elements? Thanks.

Edit:
But I tried this code, and it went through!

```
int nPt = 26;
double * y = new double[nPt];
y[224] = 0;

```

If there is no y[224], how it is possible its value is assigned?

Answer: 
When you allocate memory, using `new double[26]`, the system will get give your application a chunk of memory that has space for at least 26 x sizeof(double). The allocation function will indeed store the number 26 (or something that makes it possible to get the number 26 back in some other way) in some place inside it's meta-data for the memory allocation. 

However, the debugger won't be able to "figure out" that the number of elements is 26, it simply knows that this is a pointer to some `double` values. When you ask to seem more than 26, you are in "undefined behaviour" land - anything can and possibly WILL happen. Including that it appears perfectly as you'd "expect" (that is, the memory is readable and contains values that can be displayed as "double". Then, when you get to element 224, the debugger can't read the memory any longer (because the OS has marked it "unavailable"). That's when it stops. It could have been 50000000 [in which case it may have taken you another few hours before you got here and asked this question...]

Right. Let's say we have a computer with 100KB of RAM, for sake of simplicity. The way the processor assigns what memory is used for what purpose is in pages of 4KB at a time. So we have 25 pages. Some of those pages are your "heap" (where `new` gets its memory). One memory allocation gets a part of such a 4KB page. Say our memory happens to be on page number 18 - 18 \* 4096 = 73728 to 77823. Page 19 is marked as "not used". Our allocation within this page is 168 bytes (the first 168 bytes is used for something else) - so our address is 73896, Now, we have 26 \* 8 = 208 bytes so the "Next available byte" is 73728+376 = 74104 on the page. So, y[0] has the address 73896, and we each double takes up 8 bytes. When we get to 74104 (index 26, one outside our allocated memory), we are still on page 18, it's still "available for use" according to the processor/OS. We have to go all the way to 77824 before the processor says "You can't go there". 74104 - 77824 = 3720 bytes, or 465\* sizeof(double). But we are using memory we were told not to use. So, clearly in your test-case, the amount of "page left" is less than in my example. 

I hope this explains it fairly well. 

The reason it's 4KB is that if the processor had to keep track of EVERY single byte of memory, it would take up too much memory to track if that byte was available or not. 4KB is a good compromise between "we detect when we go outside by long enough" and "it takes up too much capacity".
> 
> So I am wondering why a double array declared with 26 length has 224 elements?
> 
> 
> 

It doesn't. Your debugger can't seem to figure out that `y` only has 26 elements.

> 
> But I tried this code, and it went through!
> 
> 
> 

```
int nPt = 26;
double * y = new double[nPt];
y[224] = 0;

```

The code has [undefined behaviour](http://en.wikipedia.org/wiki/Undefined_behavior). This doesn't mean it has to crash; it is free to fail (or not) in any way it pleases.