What will be output of the given c program?

consider the following program

 #define funct(x). x*x+x 

int main(){

int x ;

x=36+funct(5)*funct(3);

printf("%d",x);

return 0;

} what would be the output a)73. b)396.  c)109  d)360

3Comments
sanjay @sanjayrao
25 May 2017 08:32 pm

As the priority of * is higher than + it will be computed first in both funct(x) macro and also while calculating the value of x which means when u call funct(5) the following is returned

funct(5)=(5*5)+5=30

funct(3)=(3*3)+3=12

X=36+(funct(5)*funct(3))

X=36+(30*12)

X=36+360

X=396 is the answer so option b is correct

shweta @shweta1920
1 Jun 2017 05:46 am

@sanjayrao answer is 109 ...

shivani @shivani1234
27 May 2017 01:30 am
  • the crux of this question lies in analysing predefined directive
  • here ,  funct(x) is written as x*x+x  and after that evaluation begins
  • here , you need to expand expression and then calculate : x=36+funct(5)*funct(3); will be written as 36+5*5+5*3*3+3=109(here multiplication has got more priority than addition).