#include<stdio.h>
#define max(a) ((++a)*(++a)*(++a))
main(){
int a=5;
printf("%d\n",max(a));
printf("%d",a); }
this should return 6*7*8 but it is returning 7*7*8 why ?
#include<stdio.h>
#define max(a) ((++a)*(++a)*(++a))
main(){
int a=5;
printf("%d\n",max(a));
printf("%d",a); }
this should return 6*7*8 but it is returning 7*7*8 why ?
Standard says that you get undefined behavior if you modify variable multiple times between sequence points. That is what you do, so that is what you get.
Note that:
1) You have no promises about order of (++a)*(++a)*(++a)
evaluation, apart from operation (multiply) being done after it's arguments calculation (++a).
2) You are explicitly not allowed to modify same variable more than once between sequence points.