+ 2

Tell me output of this and explain.

#include<stdio.h> #define mac(x,y) x%y+x void main(){ int i=4,j=2; printf("%d\n",mac(i+j,3)); }

13th May 2017, 7:50 AM
Nachiketa Prasad
Nachiketa Prasad - avatar
2 Respostas
+ 2
define doesnt work like a function. the preprocessor just replaces every "mac(...)" before compiling. that means that i+j doesnt get calculated but every x is replaced by i+j so when the program gets compiled, you print "i+j%3+i+j". that would be "4+2%3 + 4+2" and thats 12
13th May 2017, 8:50 AM
ItsFlo
+ 2
ok ,I got it.
13th May 2017, 8:52 AM
Nachiketa Prasad
Nachiketa Prasad - avatar