+ 13

Is anyone still confused about prefix and postfx incrementing as i am??😳😵🤕

27th Apr 2019, 9:37 PM
Reedemer Kennias Mudzingwa
Reedemer Kennias Mudzingwa - avatar
8 odpowiedzi
+ 22
great explanations ~ swim ~ and Edwin Pratt
6th May 2019, 3:58 PM
Candyopoly
Candyopoly - avatar
+ 13
Thts easy enough but My problem arisesfrom something lyk this int x = 7; int y = ++x; int c = x++; Cout << y + c ;
27th Apr 2019, 9:57 PM
Reedemer Kennias Mudzingwa
Reedemer Kennias Mudzingwa - avatar
+ 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 😃
27th Apr 2019, 9:42 PM
Edwin Pratt
Edwin Pratt - avatar
+ 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
27th Apr 2019, 10:01 PM
Edwin Pratt
Edwin Pratt - avatar
+ 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
2nd Jun 2019, 10:17 PM
boneSpider
boneSpider - avatar
+ 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
18th Sep 2019, 5:28 PM
Janu Fouche
Janu Fouche - avatar