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 is the 'named constructor idiom'?
How do I swap bytes?
What is array of structure in c programming?
What is malloc and calloc?
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
What are runtime error?
How does #define work?
What is c basic?
Do you know the purpose of 'register' keyword?
What is identifiers in c with examples?
Describe the difference between = and == symbols in c programming?
Tell us the use of fflush() function in c language?
What is sizeof int in c?
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
Define C in your own Language.