Find greatest of two numbers using macro

Answer Posted / subbu

While defining macro's for each parameter enclosing brackets
is preferred. For finding out greatest of two numbers better
way writing macro is as below.

#define Greatest(a,b) ((a)>(b))?(a):(b)


If this method not followed, the in the following example
results will be wrong.


#define Product(a,b) (a*b) /* Wrong method */

Bcz if call is done as below

Product(2+3, 4+5) then result will come as (2+3*4+5) = 19
instead of 45.

Is This Answer Correct ?    20 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I invoke another program or command and trap its output?

617


Is c++ based on c?

652


What is typedf?

670


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

4504


What is pointer to pointer in c?

634






What is unary operator?

660


What is wild pointer in c?

609


What are pragmas and what are they good for?

577


What is the explanation for the dangling pointer in c?

682


What is a lookup table in c?

627


write an algorithm to display a square matrix.

2223


What is the size of structure in c?

702


differentiate built-in functions and user – defined functions.

628


Explain high-order and low-order bytes.

665


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3731