One of my friends showed me this program and asked me why the variable igets doubled.
According to my understanding MAX(i++, ++j);, this line is ifirst sent as a parameter and then increased, therefore, if the initial value iis equal 10, then the increment of the value should be 11, but it shows the increased value ias 12.
Program:
#include<stdio.h>
#define MAX(x,y) (x)>(y)?(x):(y)
void main(void)
{
int i = 10;
int j = 5;
int k = 0;
k = MAX(i++, ++j);
printf("%d %d %d",i,j,k);
}
Output:
12 6 11
Can someone please explain to me how the value increases to 12?
Thank.
source
share