Operator Priority in C - Refund

I have this statement:

return *local_stack_var2++ + 42;

Will these be the right steps to destroy it:
1. Splitting local_stack_var2
2. Add 42 to the dereferenced local_stack_var2 (the function will actually return this value)
3. Before the function finishes, it activates the post-increment, increasing the value of the object pointed to by local_stack_var2

So something like this would look like in code format?

int temp = *local_stack_var2 //step 1;  
int returnValue = temp + 42; //step 2, compiler will return THIS value     
*local_stack_var2 = *local_stack_var2 + 1; //step 3 
 return returnValue;

Thank!

+5
source share
1 answer

, ++ (postincrement) , *, . :

  • local_stack_var2, , ,
  • 42 ,

, ( , )

int* temp = local_stack_var2;
local_stack_var2 = local_stack_var2 + 1;
int retval = *temp;
reval = retval + 42;
return retval;
+8

All Articles