New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Can someone explain me what is the difference between ++a and a++?
#include <iostream> using namespace std; int main() { int a=1; int b=1; b++; ++a; cout<<a<<" , "<<b; return 0; }
2 Answers
+ 3
Luis
In your code b++ means adding 1 to your variable b, and ++a means adding 1 to both a and b and have the same value of a and b.
+ 1
a++ takes the variable and adds to it. ++a takes the variable, adds to it, then makes that new value the value of the variable.