retagged by
497 views
0 votes
0 votes

What should be the answer?

retagged by

1 Answer

1 votes
1 votes

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

Related questions

0 votes
0 votes
0 answers
2
1 votes
1 votes
1 answer
3
Prince Sindhiya asked Dec 16, 2018
791 views
The value of z after the execution of the following program isvoid f(int x) {staticint z;z=z+x;}int main() {int y=10;fork();fork();f(y);return 0;}1.30 2.20 3.40 4. 10