cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Where the array is stored when I use new
Where the array is stored when I use new
Oct 10, 2014 at 2:13pm UTC
buddha87
(58)
When we need an array, we can either:
int a[10];
or
int *a = new int[10];
delete [] a; // after you finish
So what is the difference between them? As I know if I use approach 1, the array is stored in stack while in approach 2, the array is stored in heap, ocrrect?
Thanks in advance.
Oct 10, 2014 at 2:21pm UTC
kbw
(9488)
You are correct.
Oct 10, 2014 at 2:24pm UTC
megatron 0
(471)
That is indeed correct.
The difference is, as far as my understanding goes:
When using the stack, the variable is stored inside the program itself, an address, or offset, is declared for that variable.
When using the heap, a pointer is stored and that pointer is set when the operating system sections off a portion of memory outside the program.
Oct 10, 2014 at 4:03pm UTC
buddha87
(58)
Thanks.
Topic archived. No new replies allowed.