just started learning c++ yesterday and i’d like some help in understanding post increments 🙂
Sorry if this is formated poorly! this is my first time learning programming and using this site!
This is an example of the problem:
int a = 3;
int b = a++;
cout << a << endl;
cout << b << endl;
when performing this line of code, why does the result end up in the values a = 4 and b = 3?
from my understanding I thought it would’ve resulted in a = 3 and b = 3 since variable a only gets incremented after it has returned the original value of 3.
Any help understanding would be greatly appreciated! Thank you for your time.
LearningDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.