i don't understand prefix and postfix.. help me?? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

i don't understand prefix and postfix.. help me??

28th Dec 2016, 2:05 AM
Chanju Singha
Chanju Singha - avatar
6 ответов
28th Dec 2016, 2:44 AM
James Durand
James Durand - avatar
+ 2
You're a bit backwards on it. ++a == 7 a++ == 6 Assuming that a is 6.
28th Dec 2016, 3:39 AM
James Durand
James Durand - avatar
+ 1
With prefix (++a) you do the incrementing first and then return the final value. So if a was 6 then ++a returns 7. With postfix (a++) you return the current value and then increment. So if a was 6 then a++ returns 6 but if you checked the value of a again after it would be 7. Think of it this way, prefix the ++ comes first so you add then return a. When the ++ comes second you return a then increment (postfix).
28th Dec 2016, 3:48 AM
James Durand
James Durand - avatar
0
if a = 6 then, ++a = 6, a++ = 7 is this right
28th Dec 2016, 3:24 AM
Chanju Singha
Chanju Singha - avatar
0
can you explain in details..
28th Dec 2016, 3:42 AM
Chanju Singha
Chanju Singha - avatar
0
thanks a lot durand,,,
28th Dec 2016, 6:51 PM
Chanju Singha
Chanju Singha - avatar