Why am i getting a garbage value when finding the length of the array using pointer inside the function but it is working fine in main function
here is the code:
#include<iostream>
#include<array>
using namespace std;
class fun
{
public:
void lead(int arr[]) {
cout << "empty" << endl;
}
int len(int arr[]) {
int size = *(&arr + 1) - arr;
return size;
}
};
int main() {
int arr[7] = { 1,2,3,5,7,5,6 };
cout << *(&arr + 1) - arr; // working as expected
fun obj;
int size = obj.len(arr);
cout << size; // giving garbage value
return 0;
}