Is there any difference between these two declarations?
int x[10];
vs.
int* x = new int[10];
I suppose the former declaration (like the latter one) is a pointer declaration and both variables could be treated the same. Does it mean they are intrinsically the same?
– Creates an array of size 10 integers on stack.
– You do not have to explicitly delete this memory because it goes away as stack unwinds.
– Its scope is limited to the function
doSomething()– Creates an array of size 10 integers on BSS/Data segment.
– You do not have to explicitly delete this memory.
– Since it is declared
globalit is accessible globally.– Allocates a dynamic array of size 10 integers on heap and returns the address of this memory to
z.– You have to explicitly delete this dynamic memory after using it. using: