#include <iostream>
using namespace std;
int main() {
int arr[5] = {5, 8, 1, 3, 6};
int len = *(&arr + 1) - arr;
cout << "The length of the array is: " << len;
return 0;
}
For the code above, I don't quite understand what these two pieces of codes are doing:
*(&arr + 1)
and
*(&arr)
&arr
Could someone explains? Because when I run the following two codes, I get the same output for the following:
&arr
(I think this point to the address of the first element of arr)
*(&arr)
then I don't quite understand what this do, what does the symbol *
do to &arr
(i.e. to the address here)?, because the two outputs are the same when I run them
and finally what is it exactly happening when an integer say 1 is added to the address by this code here:
&arr + 1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…