#define c(x) (x*x*x)
void main()
{
unsigned int i = 5;
printf("the value of a is %d\n\r", ((++i) * (++i) * (++i)));
}
the answer is 392 which is the multiples of 7 * 7 * 8; can any one explain the cause? and also if the variable i is declared globally i get 336
#define c(x) (x*x*x)
unsigned int i = 5;
void main()
{
printf("the value of a is %d\n\r", ((++i) * (++i) * (++i)));
}
which is the multiples of 8 * 7 * 6; this is because the increment precedence is from right to left for printf and left to right for ++ postfix operator.
there is also another compliance here which is if you declare the variable as volatile you again get 336 even when the variable is declared locally.
#define c(x) (x*x*x)
void main()
{
volatile unsigned int i = 5;
printf("the value of a is %d\n\r", ((++i) * (++i) * (++i)));
}
is this something to do with the local variable which is stored in the stack? are the variables in stack stored in a local reg and the compilation happens directly from the register and not from the memory? please explain this its bugging me from a very long time?