+ 2

Please tell me guys how to work pre-increment operator and tell me how to come here 15,66 result.

#include <studio.h> int main() { int a,b; a=10; b=(++a)+(++a)+(++a)+(++a)+(++a); printf ("A nd B is=%d %d",a,b); return 0; }

28th Aug 2018, 9:37 AM
Ashish Rastogi
Ashish Rastogi - avatar
7 ответов
+ 1
how "b" become 66
30th Sep 2018, 5:40 PM
Sachin Kumar
Sachin Kumar - avatar
0
actually it should be 15,65 in my opinion. you have a=10 in start, but every ++a operation increments it’s value to one integer more, so ++a equal 11, next +a equal 12 and finally, because you have did this operation five times, your a equals 15. incouding this knowing, you will be count b as 11+12+13+14+15 (because every ++a opeartion is returning a as one integer higher value). so now b equals 65 (because in the start you didn’t set this value, so it was zero). notation „%d” takes the next argument and prints it as a int. so a and b will be print as a int. now you get 15,65
28th Aug 2018, 5:55 PM
Aluszek
Aluszek - avatar
0
yes you are right but when we run this code then come the output is 15,66.
28th Aug 2018, 6:00 PM
Ashish Rastogi
Ashish Rastogi - avatar
0
yes 15 ,66 is right answer because when use ++a oprator for addition it get 1 plus in answer
2nd Sep 2018, 3:53 AM
Rajan Lamba
Rajan Lamba - avatar
0
but why
2nd Sep 2018, 5:28 AM
Ashish Rastogi
Ashish Rastogi - avatar
- 1
please explain me
2nd Sep 2018, 5:28 AM
Ashish Rastogi
Ashish Rastogi - avatar
- 1
салом
12th Sep 2018, 6:44 AM
Boburmirzo Samatov
Boburmirzo Samatov - avatar