문제

I have the following code:

int x;
int * xPtr = &x;

int * Get_xPtr(void);
void someFunction(int * y);

int * Get_xPtr(void)
{
    return xPtr;
}

void someFunction(int * y)
{
    ...
    ...
}

void main(void)
{
    someFunction(++Get_xPtr());
}

This code is compiling fine without the increment on the return value (address) of function Get_xPtr(), but with the increment I get the error:

"error: lvalue required as increment operand"

I guess this is not allowed syntax, but why? Is there any other way to do this or do I need to:

int * tempPtr = GetxPtr();
tempPtr++;
someFunction(tempPtr);
도움이 되었습니까?

해결책

someFunction(++Get_xPtr()); 

++Get_xptr() requires lvalue to store return value.

simple example will make some clarification

int i=0;
++i; ==>i=i+1; //result stored in i.

variable i can change

++5; //where is lvalue ?

You can use

someFunction(Get_xPtr()+1); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top