Invalid lvalue in Assignment error in C
I am getting an error described in the title when I try to run my code with this line:
(int**)newPtr = *(list + index)开发者_Go百科;
Does anyone know whats wrong?
These are my declarations
int index;
int* newPtr;
static int* list;
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.
*(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.
精彩评论