I am trying to do an exercise from Stroustup's book. The task is to create an array of 7 ints, assign its address to another variable, then print out the array value and the address. My code is below.
int main ()
{
int p0[7] = {0, 0, 0, 0, 0, 0, 0};
int* p1 = &p0;
for (int i = 0; i < 7; ++i) {
p0[i] = 2 * (i + 1);
}
for (int i = 0; i < 10; ++i) {
cout <<"Array place " << i << " has value " << p0[i] << ", and its address is " << p1 << ".\n";
}
keep_window_open();
return 0;
}
My problem is that I get a compile error on line 4 saying that "a value of type int(*)[7] cannot be used to initialize an entity of type int*". I don't understand that message nor how to correct the problem. Thanks in advance for your help.