What is the a++ for? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the a++ for?

int a = 42; do { cout << a << endl; a++; // what is this for? The int will still be 42 but if you increase it by a++ why would it be 42? Wouldn’t it be 43?? } while(a < 5); // Outputs 42

19th Dec 2017, 5:43 PM
Aiden Yi
Aiden Yi - avatar
3 Answers
+ 5
a++ is post increment and it first store the value then increment so value is store in a is 42 and then the loop is terminated so final value of a become 42 for more information https://www.sololearn.com/Discuss/407846/?ref=app
19th Dec 2017, 6:04 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
Wait so after the a++ , can I do count << a; then would it return 43
19th Dec 2017, 6:32 PM
Aiden Yi
Aiden Yi - avatar
0
Thanks man!
19th Dec 2017, 7:02 PM
Aiden Yi
Aiden Yi - avatar