It's on the stack, since as you've noted a
was allocated on the stack.
The stack is memory just like the heap; you can return a reference to part of it just like memory allocated on the heap. The only difference is in how the memory is managed.
The only thing you need to be careful of is not to access memory that's been deallocated; in the case of the stack, this happens at the end of a
's scope, while heap-allocated data has to be explicitly deleted.
In the question you refer to, a reference to a variable declared on the stack is returned from a function; in that case, the variable is destroyed when the function exits, which is why that code is wrong. In your case, however, you're returning a reference to part of data
whose lifetime matches that of the Array
object; so as long as a
has not been destroyed, it's safe to access it's data in this manner.