Q1 - Since both begin(arr) & &arr will return hexadecimal pointer location of starting of the arr, wondering what is the difference between the outputs of data types printed by the following script?
#include <iostream>
#include <typeinfo>
#include <string>
using namespace std;
int main()
{
int arr[] = {10, 20, 30, 40, 50, 60, 77};
cout << typeid(begin(arr)).name() << " , " << typeid(&arr).name() << endl;
cout << begin(arr) << " , " << &arr << endl;
return 0;
}
OUTPUT
Pi , PA7_i
0x7ffc79a99500 , 0x7ffc79a99500
Q2 - how can we get decimal representation of hex pointer location?
CodePudding user response:
For Q1:
Note that begin(arr) and &arr are different things (with different types). begin(arr) gives the pointer to the 1st element of arr with type int*, &arr gives the pointer to the array arr with type int (*)[7].
