I have this statement:
return *local_stack_var2++ + 42;
Would these be the proper steps when breaking it down:
1. Dereference local_stack_var2
2. Add 42 to the dereferenced local_stack_var2 (function will actually return this value)
3. Before the function is over, it will activate the post-increment, incrementing the value of the object pointed to by local_stack_var2
So in code format, it would look kind of something like this?
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;
Thanks!
Close, but ++
(postincrement) has higher precedence than unary *
, so it happens first. The order of operations would be:
local_stack_var2
so that it is incremented by one but the expression evaluates to the original value, not the incremented value42
to what was obtained by dereferencing the aforementioned original valueSo in code, it would be like (not precisely, but close)
int* temp = local_stack_var2;
local_stack_var2 = local_stack_var2 + 1;
int retval = *temp;
reval = retval + 42;
return retval;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With