#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6};
int size = *(&arr + 1) - arr;
return 0;
}
How does int size = *(&arr + 1) - arr;
find the size of the array exactly? I've read the explanation from geeksforgeeks and still a bit confused. I thought if you dereferenced (&arr + 1) then it would give you a nonexistent value since you're skipping ahead 6 integers, which can be anything random in that memory address? And also, if you're able to dereference (&arr + 1) to an int type, then how are you able to subtract that value from arr
?