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
What are pragmas and what are they good for?
given post order,in order construct the corresponding binary tree
How do I copy files?
find the sum of two matrices and WAP for it.
What is 1f in c?
what is the format specifier for printing a pointer value?
What is linear search?
write a program to create a sparse matrix using dynamic memory allocation.
What is echo in c programming?
Can you write the function prototype, definition and mention the other requirements.
Under what circumstances does a name clash occur?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
What are comments and how do you insert it in a C program?
Is c is a procedural language?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?