I understand(not completely why, though) that instances of primitive types such as int, float are stored on the stack and are not heap allocated. But I am a bit confused about how arrays of primitive types are stored and accessed. I have this question because System.Array is a reference type. And reference types are heap allocated.
int[] integers = {1,2,3,4,5};
How are these individual integers stored and accessed on the memory?
Your “understanding” is flawed, basically. Value type values are sometimes stored on the stack – but not when part of an array or any other heap-based object. It’s unfortunate that some people choose to make such a blanket statement around value types living on the stack, which then confuses others 🙁
Besides, the stack/heap distinction is an implementation detail…
See my article on memory for some more details, but definitely read Eric Lippert’s blog post (linked in the previous paragraph) for more philosophical considerations. (Read his other posts on value types for even more information.)