0

Need help or explanation.. are postfix and prefix in c++, c#, php or any language same ? when actually the value +1 or -1 ?

in example : x = 0 x++ = ? ++x = ? y = 3 z = y++ z = ++y I often false doing that math on challenge, with different language.. still confuse 😞

26th May 2017, 1:58 AM
Mugfirfauzy Siregar
Mugfirfauzy Siregar - avatar
6 Respuestas
+ 3
1) x = 0 x++ = ? ++x = ? 2) y = 3 z = y++ z = ++y x++ = ++x = 1 The only difference is that x++ will returns the value of x first then add one to it, but in ++x it will change the value of x then it will returns the new value (x+1). anyways, you will understand by seeing example: assuming that y=3 if we wrote z = y++, in this case z = 3 and y = 4 if we wrote z = ++y, in this case z = 4 and y = 4
8th Jul 2017, 3:54 AM
Oussama Bezzad
Oussama Bezzad - avatar
+ 2
THEY ARE SAME IN C++ AND JAVA NOT CONFIRM ABOUT IN OTHER LANGUAGES
26th May 2017, 4:41 AM
Jain Rishav Amit
Jain Rishav Amit - avatar
+ 1
this is because , if you are using x++ at the same time of expression , then current value of x will be used and then increment will take place , so x will be 1 only and when we use the value of x after evaluation of x++ then the value of x will be incremented ..... consider following examples , with x= 1 as base and language as c++: 1. cout<<x++; // this will give answer as 1 as we are using as x at the same time and now next time we will use x it will be 2 2. x++ ; cot<<c; // this will give 2 as output as x has already been increamted before 3. cout<<x<<x++<<x++<x; // output : 1123
26th May 2017, 6:55 AM
Jain Rishav Amit
Jain Rishav Amit - avatar
+ 1
practising it again and again, this will increase your speed if you dont get your answer due to less time then while checking your answer do not directly check the answer, instead try to solve it and then check answer
26th May 2017, 7:04 AM
Jain Rishav Amit
Jain Rishav Amit - avatar
0
in some questions, when the x = 1, x++, so x = 1. But in other question x = 2.. this make me confuse
26th May 2017, 6:47 AM
Mugfirfauzy Siregar
Mugfirfauzy Siregar - avatar
0
so hard to count, even harder in array index, and not much time given on challenge
26th May 2017, 7:01 AM
Mugfirfauzy Siregar
Mugfirfauzy Siregar - avatar