#include <iostream>
using namespace std;
int main (void)
{
int * p = new int(40); // here `p` points to an array having space for 40 ints or space allocated is 40 bytes?
for (int i = 0; i < 2; i++)
cin>>p[i];
cout<<sizeof(p)<<"\n"; // here, the output should be size of array since p points to an array
int arr[5] = {1,2,3,4,5}; // since, here it will output 20 (space allocated for the entire array)
cout<<sizeof(arr)<<"\n";
return 0;
}
So, I have two questions (the first two comments in the program)
Here
p
points to an array having space for 40 ints or space allocated is 40 bytes?Here, the output should be size of array since
p
points to an array because technically speaking,arr
is also a pointer and when we do*arr
it references to the first element of the array.