Why is & amp; array! = & Amp; Array [0]?
source link: https://www.codesd.com/item/why-is-array-array-0.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Why is & amp; array! = & Amp; Array [0]?
int a[10];
printf("%p\n", a);
printf("%p\n", &a[0]);
Yields:
0x7fff5606c600
0x7fff5606c600
Which is what I expect. Now, in D, I'm trying this (obviously no use case, just fooling around):
int[] slice = [...];
writeln(&slice);
writeln(&slice[0]);
Yields:
7FFF51600360
10E6E9FE0
Why the difference? Looks like a completely different memory segment. (Though it just occurred to me that perhaps arrays in D aren't just adjacently allocated ints?)
in D an array is essentially a struct with a pointer and a length field and is treated as such
to get the address to the first element you can query the ptr field
Related Articles
why for any array C this expression contains a [7] == 7 [a]
why a char array must end with a null character
Why does indexing arrays numpy with square brackets and commas differ in behavior?
Why are the Arrays invariable, but covariant Lists?
Why in_array (1, array ('1: foo')) returns TRUE?
Why builders with array as parameter previous to constructors with Object in parameter [java]?
Why is the array object not editable?
Why use char array to create a buffer
Why do Java arrays have a fixed length?
Why are char array and int array printed as different things?
Why does var_dump (array) cause a 500 error in Magento?
Why does the array that I return in my __construct class available in the following function?
(Why) the parameter `array [NaN]` does nothing?
Why is the array of the param [] object depressed if you pass an array int []?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK