+ 3
Helo guys , I am having trouble understanding increments ..what is the difference between z++ & ++z ?
C++ increments /decrements
4 odpowiedzi
+ 4
Let me give you an illustration.
z=0;
z++; // z is still 0
z; // now z is 1
++z; // z is 2.
+ 4
Look this equation
imagine x=5
y=x++
above equation can be divided in to two parts
1. y=x
2. x=x+1
after executing these 2 still the value of y is 5.
if the eqaution was like this
y=++x
1. x=x+1
2. y=x
now the value of y is 6;
Hope You'll understand it
+ 3
with z++, the variable z is used and then incremented while ++z means that z is incremented before it is used.
+ 2
When ++ is before the variable, it as increased by 1 e.g x=4 cout<<++x; output is 5: and when the ++ is after the variable it stays the same at the moment e.g x=4 cout<<x++; output is 4