edited by
670 views
2 votes
2 votes

What is the output of the following C-program?
Please provide a sound explanation too.
 

#include<stdio.h>
#define f(x) x*x+x
main()
{
    int x;
    x=f(8)*f(5);
    printf("%d",x);
}



A)266 B)269 C)2160 D)216

edited by

2 Answers

Best answer
4 votes
4 votes
Your  code will be more simplified as-:
#include<stdio.h>
#define f(x) x*x+x
main()
{
    int x;
    x=f(8)*f(5);
    x=((8*8)+((8*5)*5)+5)
    printf("%d",x);
}

Reason-:define simply replaces the replaces the variable unlike a function which execute it.

 x=((8*8)+((8*5)*5)+5)=269

here * has more precedence than + and * i left associate ,so it will be executed in this order.

selected by
0 votes
0 votes
During compilation, 6th line will become x=8*8+8*5*5+5 which will evauate to 269.

Related questions

1 votes
1 votes
1 answer
1
Desert_Warrior asked Jun 11, 2016
1,290 views
int main() { char boolean[][6]={"TRUE","FALSE"}; printf("%s",boolean[(unsigned int)-1 == ~0]); }
2 votes
2 votes
0 answers
2
Nandkishor3939 asked Jan 13, 2019
613 views
Can any one explain whats happening in side the green area due to dynamic programming ?
0 votes
0 votes
1 answer
3
SSR17 asked Feb 29
210 views
#include <stdio.h int main() { int i = -1; int x = (unsigned char)i; printf("%d", x); return 0; }output is 255 , but please explain how
2 votes
2 votes
1 answer
4
rupamsardar asked Aug 30, 2023
468 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...