What will be printed in the output and why include main in
What will be printed in the output? and why?
#include <stdio.h>
main( )
{
int a=3,b,d=12;
float c,f=7.2;
b=a++ * 2;
printf(\"%d %d\ \",a,b);
b=++a *2;
printf(\"%d %d\ \",a,b);
c = f+d/10 ;
f += d%8;
printf(\"%f %f\ \",c,f);
}
Solution
output is:
4 6
5 10
8.20000 11.20000
in first print statement : a=3,b=0 and d=12
 b=a++ * 2;   
 
 //intially b=0,a=3,d=12, b=a++ * 2 =>b=3*2 =>b=6 and
 then a will become 4 beacuse a is post increment it first assign it cuurent value and then it
 will increment
 so here a=4 and b=6;
in second print statement : a=4,b=6 and d=12
 b=++a *2;
 
 //here a is pre increment it means it will first it value and then it will be assigned
 so here a value is 4 so it will first increment to 5 ,b=5*2=>b=10
 so here a=5 and b=10;
 in third print statement : a=5,b=10 and d=12 ,c and f is float variable and f=7.2
 c = f+d/10;
 f += d%8;
here f=7.2 and d=12 acccording to bodmas rule first division will be done and then addition will done
 so c=f+(12/10) =>as d is int it will cut decimal values so c=f+1 => c=7.2+1 =>8.20000
f+=d%8;=>here d=12 so f+ means it will increment it value by its assigned value that is
 f+=12%8 => f+=4 =>as f value is 7.2 so it will increment 7.2 by value 4 that f=11.20000

