Find the output of the following code snippet:

#include

#define MULTIPLY(a,b) a/b

int main(){

  int x=5, y=2, result; 

  result = MULTIPLY(y+x,y+x);

  printf("%d",result);

  return 0;

A

1

B

7

C

9

D

Runtime error

উত্তরের বিবরণ

img

Answer: ) 9
Explanation:

Macro:

#define MULTIPLY(a,b) a/b is a macro, not a function.

So:

result = MULTIPLY(y+x, y+x);
According to macro definition

result  = y + x / y + x;
This happens because macros do not add parentheses automatically.

In C: Operator precedence 

1.     / has higher precedence than +.

2.     So y + x / y + x evaluates as: y+(x/y)+x

Put x = 5, y = 2

                                    2+ (5/2) +5

                                  =2+2+5    (Integer division: 5 / 2 = 2)

                                  =9

So, Output = 9

 

Unfavorite

0

Updated: 2 days ago

Related MCQ

 Which one is true for a B+ tree? 

Created: 2 days ago

A

Internal nodes store only actual data

B

Leaf nodes store actual data

C

Does not maintain sorted data

D

Retrieval of data is slower

Unfavorite

0

Updated: 2 days ago

 Which data structure allows insertion at one end and deletion at the other end?

Created: 2 days ago

A

Stack

B

Tree

C

Queue

D

Graph

Unfavorite

0

Updated: 2 days ago

 A 16-bit address bus can address a maximum of ____ KB memory. 

Created: 2 days ago

A

16

B

32

C

64

D

128

Unfavorite

0

Updated: 2 days ago

© LXMCQ, Inc. - All Rights Reserved

Developed by WiztecBD