0

What is the output and why?

#define square(x)(x*x) Int main() { Int x, y=1; x=square(y+1); printf("%d\n",x); return 0; }

12th Jul 2019, 1:18 PM
Ankul Chaudhary
Ankul Chaudhary - avatar
2 Answers
+ 7
#define is preprocessor directive . It creates a macro. It'll replace square(x) with (x*x) in code. Remember macro arguments are NOT evaluated before macro expansion. Meaning it'll first replace all square(x) with (x*x ) without evaluating values of x . Here square(y+1) is replaced with y+1*y+1 then after expansion it evaluates this expression. y+1*y+1=>1+1*1+1 Due to operator precedence multiplication will be performed firstl 1+(1*1)+1=>1+1+1=>3 Thus output is 3 Read this also. https://www.sololearn.com/discuss/1874614/?ref=app refer this for more info https://www.geeksforgeeks.org/interesting-facts-preprocessors-c/
12th Jul 2019, 1:39 PM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar