c++ - Difference between a static and dynamic array -
Friends I was just playing around with some pointer programs and felt that the GCC (and probably standard standard) Differentiates and dynamic arrays.
In an array there is a place holder for the address of elements, while for the stable array, there is no memory place where the compiler element stores the initial address of the array.
I have an example program for displaying my confusions.
#include & lt; Iostream & gt; # Key (zero) {int_static [10]; Int * _dynamic; _dynamic = new int [10]; Std :: Court & lt; & Lt; "_static =" & lt; & Lt; _static & lt; & Lt; "& Amp; _static =" & lt; & Lt; & Amp; _static & lt; & Lt; "& Amp; _static [0] =" & lt; & Lt; & Amp; _static [0] to be & lt; & Lt; Std :: endl; Std :: Court & lt; & Lt; "_dynamic =" & lt; & Lt; _dynamic & lt; & Lt; "& Amp; _dynamic =" & lt; & Lt; & Amp; _dynamic & lt; & Lt; "& Amp; _dynamic [0] =" & lt; & Lt; & Amp; _dynamic [0] is followed by & lt; & Lt; Std :: endl; Return 0; } For the above program, _static and & amp; _static [0] Return the same address to the expected lines However, & amp; _static also the other two returns as a single address then, _static and & amp; _static Refer to the same number (or address we want to call it) as expected, _dynamic and & amp; _dynamic indicate different locations. So, why did the C standard say that _static and & amp; _static should mention the same place. It seems misleading. One reason I think is that & amp; _static does not matter much Can anyone help me with this illusion?
Actually _static and & amp; _static is not the reason for not mentioning the same place because you use _static in that context, in which it is decayed in an indicator, this is the reason that you Use, you create refer to them in the same place. But before you did not do that - there was one array and the other was an indicator they could not be equal because they were basically different things.
Comments
Post a Comment