+ 4

i= i++ + ++i - i-- - --i; why the output of this procces is 0?

need answer immediately

6th Oct 2017, 11:25 AM
SingleName
SingleName - avatar
23 Answers
+ 9
step by step i=5 i++ means i=5 no change(nc) ++i means previous ++ is 5 turn into 6 then again ++ 7 i=7 i-- nc i=7 --i means previous -- is 7 turn into 6 then again -- 5 i=5 5+(7-7)-5 5-5 0
6th Oct 2017, 12:31 PM
Scooby
Scooby - avatar
+ 9
I think that if i=5 i++ in operation 5 is used but i becomes 6 ++i is 7 i-- then 7 is used but i becomes 6 --i is 5 so you have 5+7-7-5=0 and when you remove the i-- - --i and run the process i=i++ + ++i; then the result in 5+7=12
6th Oct 2017, 12:26 PM
m abrate
m abrate - avatar
+ 7
what is the initial value of i?
6th Oct 2017, 11:38 AM
Scooby
Scooby - avatar
+ 7
i new in programming but i think: int y = ++x; // first: increment x, then: assignment int y = x++ // firsr: assignment, then: increment x int i = 5; i = (i++) + (++i) - (i--) - (--i) // a + b - c - d a = i++ // a = 5, i = 6 b = ++i // b = 7, i = 7 c = i-- // c = 7, i = 6 d = --i // d = 5, i = 5 // i = 5 + 7 - 7 - 5 = 0
6th Oct 2017, 12:20 PM
Podretyz
Podretyz - avatar
+ 6
right is i++ mean no change ++i mean increment vice versa in -- decrement its count to right to left not left to right 5+(6-6)-5 5-5 0
6th Oct 2017, 11:58 AM
Scooby
Scooby - avatar
+ 6
mark ur best ans @name
6th Oct 2017, 12:18 PM
Scooby
Scooby - avatar
+ 6
right is the i=5; i++ is 5 ++i is 7 i-- is 7 --i is 5?
6th Oct 2017, 12:19 PM
Scooby
Scooby - avatar
+ 5
check right previous was wrong
6th Oct 2017, 11:59 AM
Scooby
Scooby - avatar
+ 5
because its post decrement then stay last value.. and then come pre decrement so it become 5 again ☺
6th Oct 2017, 12:02 PM
Scooby
Scooby - avatar
+ 5
i=(5+5-5-5)+1-1=0 so,the output will be zero always remember before doing addition or substraction in these kind of problems do preincrement for sure,at the end do the post increment.
6th Oct 2017, 12:06 PM
David Fernando
David Fernando - avatar
+ 5
its count to right to left not left to right
6th Oct 2017, 12:08 PM
Scooby
Scooby - avatar
+ 5
no problem love ur community do some for ur community then better sololearn ☺
6th Oct 2017, 12:49 PM
Scooby
Scooby - avatar
+ 4
sorrt for incompletw question
6th Oct 2017, 11:39 AM
SingleName
SingleName - avatar
+ 3
thanks for the answer guys in understand now :) luv u all
6th Oct 2017, 12:47 PM
SingleName
SingleName - avatar
+ 2
5
6th Oct 2017, 11:38 AM
SingleName
SingleName - avatar
+ 2
i++ is still 5 and ++i will increment to 6?
6th Oct 2017, 11:58 AM
SingleName
SingleName - avatar
+ 2
nice but can i ask u why i-- is 6?
6th Oct 2017, 12:00 PM
SingleName
SingleName - avatar
+ 2
is*
6th Oct 2017, 12:07 PM
SingleName
SingleName - avatar
+ 2
Yeahh i love ur community too .. :)
6th Oct 2017, 12:56 PM
SingleName
SingleName - avatar
+ 1
because when i remove the i-- - --i and the i run the process i=i++ + ++i; then the result in 12
6th Oct 2017, 12:06 PM
SingleName
SingleName - avatar