int size = *(&arr + 1) – arr; Why this &arr is going to point at last element and giving exact size of array? [duplicate]

  arrays, c++
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    int  arr[] = {1, 2, 3, 4, 5, 6};

    int size = *(&arr + 1) - arr;

    cout << "Number of elements in arr[] is ";
         << size;

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT