Find size of array without using sizeof
arrays, c, sizeof
Solution
`&arr` is a pointer to an array of 100 `int`s.
The `[1]` means "add the size of the thing that is pointed to", which is an array of 100 `int`s.
So the difference between `(&arr)[1]` and `arr` is 100 `int`s.
(Note that this trick will only work in places where `sizeof` would have worked anyway.)
Problem
I was searching for a way to find the size of an array in C without using `sizeof` and I found the following code: ``` int main () { int arr[100]; printf ("%d\n", (&arr)[1] - arr); return 0; } ``` Can anyone please explain to me how is it working?