Discussion
Consider the following statements
#define hypotenuse(a, b) sqrt (a*a+b*b)
The macro call hypotenuse(a+2,b+3);
Answer: D
Correct answer: Find the square root of 3*a + 4*b + 5
The macro body has no parentheses round its parameters, so the arguments are pasted in as raw text:
sqrt(a+2*a+2 + b+3*b+3)
Multiplication binds tighter than addition, so this is \(\sqrt{a + 2a + 2 + b + 3b + 3} = \sqrt{3a + 4b + 5}\) - nothing like a hypotenuse. Writing #define hypotenuse(a, b) sqrt((a)*(a) + (b)*(b)) is what makes the macro behave as intended.
No comment is present. Be the first to comment.
Loading…
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