0

  #include<stdio.h>  #include<conio.h>  void main(){  int a,i=4;  a=- -i+- -i+- -5;  printf("%d %d",a,i);  } return x*3;  }

please explain the output of this

25th Dec 2016, 8:32 AM
Arpitha G R
Arpitha G R - avatar
5 Answers
0
the output will be 9 2 what --i does is first it decreases i by one then uses its value and what i-- does is it first uses its value then decreases it..... so here first we have --i so i=3 and 3 is used then it again does --i so now i=2 and then --5 becomes 4. So a becomes 3+2+4 i.e. 9....
25th Dec 2016, 4:14 PM
Dhairya Karna
Dhairya Karna - avatar
0
A lot of people have this confusion as to when in i++ will the value increment....its rather simple....it increases when the compiler encounters a ;.....example i=4; i++// i has the value 4 here ; // after encountering ; it's value becomes 5
25th Dec 2016, 4:16 PM
Dhairya Karna
Dhairya Karna - avatar
0
but the actual answer is 13 4 I didn't get how so please can u interpret that
25th Dec 2016, 4:26 PM
Arpitha G R
Arpitha G R - avatar
0
then you must be using a c compiler rather than a c++ compiler as the c compiler doesn't get the meaning of --i
26th Dec 2016, 1:06 AM
Dhairya Karna
Dhairya Karna - avatar
0
but even c compiler will take pre increment right
26th Dec 2016, 1:40 AM
Arpitha G R
Arpitha G R - avatar