#include<stdio.h>
int main(void) {
int arr[3]={1,2,3};
return 0;
}
Now what will *(&arr) give me and why? I want a detailed explanation. Don’t just tell me how * and & cancel out 😛
I want to know how the compiler interprets this expression to give the desired result.
&arrcreates a pointer to the array – it’s of typeint (*)[3], and points at the arrayarr.*&arrdereferences that pointer – it’s the array itself. Now, what happens now depends on what you do with it. If you use*&arras the subject of either thesizeofor&operators, then it gives the size or address of the array respectively:However, if you use it in any other context, then it is evaluated as a pointer to its first element:
In other words:
*&arrbehaves exactly likearr, as you would expect.