Discussion
Consider the following statement
#define hypotenuse (a, b) sqrt (a*a + b*b);
The macro-call hypotenuse (a + 2, b + 3);
Answer: D
Correct answer: finds square root of 3*a + 4*b + 5
The macro's parameters are not parenthesised in the replacement text, so the arguments are substituted textually and the surrounding operators then bind more tightly than intended:
sqrt(a+2*a+2 + b+3*b+3)
which is \( \sqrt{a + 2a + 2 + b + 3b + 3} = \sqrt{3a + 4b + 5} \). The intended \( (a+2)^2 + (b+3)^2 \) is not what results. This is the standard argument for parenthesising every parameter and the whole replacement text in a function-like macro.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development