1

I am getting an error described in the title when I try to run my code with this line:

(int**)newPtr = *(list + index);

Does anyone know whats wrong?

These are my declarations

int index; 
int* newPtr;
static int* list;
1
  • Is the declaration of newPtr int* newPtr or (int**)newPtr? You show both...
    – sarnold
    Commented Feb 27, 2011 at 10:03

2 Answers 2

2

There are a couple of errors in the code:

  • newPtr is declared as a pointer-to-integer, but you are casting it to pointer-to-pointer-to-integer which is wrong.

  • list+index is also a pointer-to-integer to *(list+index) is an integer pointed to by (list+index). But you are trying to assign that to newPtr (which is also casted to wrong type as above).

Possibly you intended to do this:

newPtr = list+index;

and get a pointer-to-integer located at list + index-th location.

0

*(list + index) returns an int. If you want a pointer out, just use

newPtr = list + index;

int** means a pointer to an int pointer, that seems to have no business in there.

Not the answer you're looking for? Browse other questions tagged or ask your own question.