Unary operation are sometimes suicidal.Mess up with C code

119 views Asked by At

Code in C language.

#include<stdio.h>
#define PRODUCT(x) ( x * x * x)
int main()
{
  int i =5,k;
  k = PRODUCT( ++i );
  printf("i is :%d ",k);
  return 0;
}

My Question is why i is : 392? According to me output should be 336. (because 6 * 7 * 8 = 336)

Am I really messed up here??

1

There are 1 answers

0
Dayal rai On BEST ANSWER

Preprocessed code will have

( ++i * ++i * ++i)

which have Lack of sequence point between the two execution on same variable resulting Undefined behaviour.