#define prod(a,b) a*b int main() { int x=3,y=4; printf("%d",prod(x+2,y-1));…

2024

#define prod(a,b) a*b

int main()

{

int x=3,y=4;

printf("%d",prod(x+2,y-1));

return 0;

}

  1. A.

    10

  2. B.

    20

  3. C.

    15

  4. D.

    0

Attempted by 142 students.

Show answer & explanation

Correct answer: A

Step 1: The macro prod(a,b) is defined as a*b, which expands directly without parentheses.

Step 2: In the function call prod(x+2,y-1), the macro expands to x+2*y-1.

Step 3: With x = 3 and y = 4, substitute the values: 3 + 2*4 - 1.

Step 4: Apply operator precedence: multiplication first, so 2*4 = 8.

Step 5: Then evaluate: 3 + 8 - 1 = 10.

Thus, the output is 10.

हिन्दी उत्तर:

चरण 1: मैक्रो prod(a,b) को a*b के रूप में परिभाषित किया गया है, जो बिना कोष्ठकों के सीधे विस्तारित होता है।

चरण 2: prod(x+2,y-1) कॉल में, मैक्रो x+2*y-1 में विस्तारित होता है।

चरण 3: x = 3 और y = 4 के साथ, मानों को प्रतिस्थापित करें: 3 + 2*4 - 1।

चरण 4: ऑपरेटर प्राथमिकता का अनुसरण करें: गुणा पहले, इसलिए 2*4 = 8।

चरण 5: फिर मूल्यांकन करें: 3 + 8 - 1 = 10।

इसलिए, आउटपुट 10 है।

Explore the full course: Coding For Placement