문제

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??

도움이 되었습니까?

해결책

Preprocessed code will have

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top