in Programming in C retagged by
488 views
0 votes
0 votes

What should be the answer?

in Programming in C retagged by
by
488 views

2 Comments

@DAWID15 what is answer ???
and kindly say is kabir bhaiyya correct.

0
0

Yes he’s right. The answer is C.

Thanks @Kabir5454

1
1

1 Answer

1 vote
1 vote

The answer will be (C) .

Macro sometimes also called by the name unsafe function as it may evaluate its argument more than once .

Here given ,

$a=10$ , $b=11$, $c=12$.

The definition of the macro is ,

#define greater($x$,$y$) $(x)>(y)$ ? $(x) :(y)$

$c$=greater$(a++$,$++b)$

now the invocation of the macro looks like ,

$c= $($a++$)>($++b$)$ ? $($a++$) :($++b$)

so

      1)first a increment to 11 .

       2) b increases to 12

        3) comparison occurs between them .

         4) as 12 is greater that 11 so , $++b$ will be our answer.

         5) due to $++b$ value of b again increases to 13 .

         6) we assign value of $C=13$ .

so our required answer will be option (C) .

ref: – https://wiki.sei.cmu.edu/confluence/display/c/PRE31-C.+Avoid+side+effects+in+arguments+to+unsafe+macros

edited by

2 Comments

kabir bhai,my ans is same ,but i think you mistaken at step 1 as “a” will be first used then incremented
0
0
excellent explanation
0
0