I’ve just started learning cpp and I leaned that array name decays into pointer that points to memory address of first element of that array but
when I created a pointer that point to same first index of array both of them print different memory address.
#include <iostream>
using namespace std;
int main()
{
int array[4] = {1, 3, 5, 7};
cout << "Memory Address of array is:n" << array << "n";
int *myp;
myp = &array[0];
printf("Memory Address of myp is: %pn", myp);
return 0;
}
Memory Address of array is:
0x7718dff8c0
Memory Address of myp is : 0000007718dff8c0
New contributor
Momin Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.