Invalid conversion from 'int*' to 'int' from section "Subscripts and Pointers" in C++ Primer

12 views Asked by At

This code is an excerpt from C++ Primer fifth edition. I keep getting this error, "Invalid conversion from 'int*' to 'int'. Any ideas on how to fix this? Also, can anyone clarify the difference between int* a = b, versus int a = b, versus int a = b?

I tried reading the chapters that covered pointers, dereferences, and references. No luck. I haven't tried anything else as I don't know what to change.

Here is the code below.

using namespace std;

int main() { 

int ia[] = {0,2,4,6,8};
int i = ia[2];
int *p = ia;

i = *(p+2);

*p = &ia[2]; 
int j = p[1];
int k = p[-2]; 

cout << j;
cout << k;
} 
0

There are 0 answers