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 😞
6 odpowiedzi
+ 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
+ 2
THEY ARE SAME IN C++ AND JAVA
NOT CONFIRM ABOUT IN OTHER LANGUAGES
+ 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
+ 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
0
in some questions, when the x = 1, x++, so x = 1. But in other question x = 2.. this make me confuse
0
so hard to count, even harder in array index, and not much time given on challenge