Consider the following statements #define hypotenuse (a, b) sqrt (a*a+b*b);…

2015

Consider the following statements

#define hypotenuse (a, b) sqrt (a*a+b*b); 

The macro call hypotenuse(a+2,b+3);

  1. A.

    Finds the hypotenuse of a triangle with sides a+2 and b+3

  2. B.

    Finds the square root of (a+2)2 and (b+3)2

  3. C.

    Is invalid

  4. D.

    Find the square root of 3*a + 4*b + 5

Attempted by 2 students.

Show answer & explanation

Correct answer: D

The macro definition lacks parentheses around parameters, causing direct text substitution during preprocessing. Substituting a+2 for a in the expression a*a results in a+2*a+2. Due to operator precedence, this simplifies algebraically to 3a + 2. Similarly, substituting b+3 for b in b*b yields 4b + 3. Combining these results, the total expression inside the square root becomes 3a + 4b + 5.

Explore the full course: Isro