Consider the following statements
#define hypotenuse (a, b) sqrt (a*a+b*b);
The macro call hypotenuse(a+2,b+3);
(A) Finds the hypotenuse of a triangle with sides a+2 and b+3
(B) Finds the square root of (a+2)2 and (b+3)2
(C) Is invalid
(D) Find the square root of 3*a + 4*b + 5
Answer: (D)
Explanation:
A macro is defined with, hypotenuse (a, b) sqrt (a*a+b*b);
call hypotenuse(a+2,b+3);
hypotenuse = sqrt (a+2*a+2 + b+3*b+3)
= sqrt (a + 2a + 2 + b + 3b + 3)
= sqrt (3a + 4b + 5)
So, option (D) is correct.
Note: correct way to define this macro is:
#include <stdio.h>
#include <math.h>
#define hypotenuse(a, b) sqrt(a*a+b*b)
int main()
{
printf ( "%f" , hypotenuse (1+2, 2+3));
return 0;
}
|
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 May, 2018
Like Article
Save Article