Message from C, C++ discussions

January 2020

— Mat

— 

#include<stdio.h>

#define MAN(x, y) ((x)>(y)) ? (x):(y);


int main()

{

    int i=10, j=5, k=0;

    k = MAN(++i, j++);

    printf("%d, %d, %dn", i, j, k);

    return 0;
How d ans of dis question will be 12, 6,12??

}

— Because of the macro you have defined

before execution, MAN will be replaced with the whole defination

#include<stdio.h>

#define MAN(x, y) (x)>(y)?(x):(y);


int main()

{
int i=10, j=5, k=0;

k = MAN(++i, j++);
// This line will look like
// k = (++i)>(j++)?(++i):(j++);

printf("%d, %d, %dn", i, j, k);

return 0;
}


and when you'll execute this
You'll get 12, 6, 12

Message permanent page

— You should tell him why i is incremented by 2 and j by 1

— Do you know how the ternary operator works?

— Please, avoid the use of d in place of the or th and ans in place of answer

— I guess he is thinking that

 k = MAN(++i, j++);
this will be executed by calculating the value of ++i and j++ first and then sending them as arguements to the macro
which in this case will result
k = MAN(11, 5) //j++ will pass 5 but the value of j will be 6

Message permanent page

— Human beign have brain so i have

— Good

— It took Google translator 22mins to decode it

— Because it is a genius question so google take time to decode for this

— Ohh sorry I didn't know that it was a question