+ 13
Is anyone still confused about prefix and postfx incrementing as i am??š³šµš¤
8 Answers
+ 22
great explanations ~ swim ~ and Edwin Pratt
+ 13
Thts easy enough but
My problem arisesfrom something lyk this
int x = 7;
int y = ++x;
int c = x++;
Cout << y + c ;
+ 10
Hey there š
In C++, when we prefix increment, we add 1 before returning a value
For example:
int a = 1;
cout << ++a;
// Output 2
If we postfix increment, we use the current value before incrementing it:
int a = 1;
cout << a++;
cout << a;
// Output:
1
2
Hope it helps š
+ 10
Okay, all you need to remember is everything happens in sequence:
x = 7;
x + 1
y = x
# x is 8
c = x
x + 1
+ 9
I understand ++ and -- prefix/postfix most of the time in challenges, but it can still confuse me. Here at line 340 in the drawBlackKeys function I thought I was being clever by both referring to the position in the array while also advancing it, might not have been the best way to structure it since any black key label up next for printing has to be referred to 4 positions over which is not intuitive but was the only way I could make it work as pos++ on a line by itself inside the for loop didn't seem to do it
https://code.sololearn.com/cVJ1d1urW7ap/?ref=app
+ 2
If it is before the the integer is increase and the the line of code is exsecuted if it is after the the line of code is exsecuted and the the integer is increased