Compiler-Design
September 10, 2024Probability
September 10, 2024Compiler-Design
Question 318 |
Consider the following statements
#define hypotenuse (a, b) sqrt(a*a+b*b);
The macro call hypotenuse(a+2,b+3);
Finds the hypotenuse of a triangle with sides a+2 and b+3 | |
Finds the square root of (a+2)2 and (b+3)3 | |
Is invalid | |
Find the square root of 3*a + 4*b + 5 |
Question 318 Explanation:
Given macro call is hypotenuse(a+2,b+3)
Macro definition is
hypotenuse (a, b) sqrt (a*a+b*b)
Substitute a+2 and b+3 inplace of a and b respectively
Then
sqrt(a+2*a+2+b+3*b+3)
// operators are addition(+) and multiplication(*) present in the above expression
Multiplication (*) operators has highest priority than addition (+) and associativity is Left to right.
First 2*a is evaluated which is 2a Later 3*b which is 3b.
Then the expression becomes
sqrt(a+2a+2+b+3b+3)
=sqrt(3a+2+b+3b+3)
=sqrt(3a+4b+5)
Macro definition is
hypotenuse (a, b) sqrt (a*a+b*b)
Substitute a+2 and b+3 inplace of a and b respectively
Then
sqrt(a+2*a+2+b+3*b+3)
// operators are addition(+) and multiplication(*) present in the above expression
Multiplication (*) operators has highest priority than addition (+) and associativity is Left to right.
First 2*a is evaluated which is 2a Later 3*b which is 3b.
Then the expression becomes
sqrt(a+2a+2+b+3b+3)
=sqrt(3a+2+b+3b+3)
=sqrt(3a+4b+5)
Correct Answer: D
Question 318 Explanation:
Given macro call is hypotenuse(a+2,b+3)
Macro definition is
hypotenuse (a, b) sqrt (a*a+b*b)
Substitute a+2 and b+3 inplace of a and b respectively
Then
sqrt(a+2*a+2+b+3*b+3)
// operators are addition(+) and multiplication(*) present in the above expression
Multiplication (*) operators has highest priority than addition (+) and associativity is Left to right.
First 2*a is evaluated which is 2a Later 3*b which is 3b.
Then the expression becomes
sqrt(a+2a+2+b+3b+3)
=sqrt(3a+2+b+3b+3)
=sqrt(3a+4b+5)
Macro definition is
hypotenuse (a, b) sqrt (a*a+b*b)
Substitute a+2 and b+3 inplace of a and b respectively
Then
sqrt(a+2*a+2+b+3*b+3)
// operators are addition(+) and multiplication(*) present in the above expression
Multiplication (*) operators has highest priority than addition (+) and associativity is Left to right.
First 2*a is evaluated which is 2a Later 3*b which is 3b.
Then the expression becomes
sqrt(a+2a+2+b+3b+3)
=sqrt(3a+2+b+3b+3)
=sqrt(3a+4b+5)
Subscribe
Login
0 Comments