+ 2

how ++a and a++ works ? help with example

17th Aug 2016, 7:14 PM
Bishal Nath
Bishal Nath - avatar
3 Answers
+ 4
First, it's clearly presented in the course. ++a is adding 1 to variable a and then use it, a++ is first using the variable, then adding 1 to it. int a = 3; int y; y = a++; //y=3, a=4 // OR y = ++a; //y=4, a=4
17th Aug 2016, 8:21 PM
Tamas Szekffy
Tamas Szekffy - avatar
+ 3
both are used to increment a value by one but ++a increment first before printing a number and a++ stores the value in memory but prints the original value not the incremented one and when u use a(variable) again it will use the incremented value rather than the original one. for e.g. int a=3; cout<< a++ << ++a <<endl; court<< a; return 0; output 3 5 5
17th Aug 2016, 8:19 PM
Asim
Asim - avatar
0
Edit court to cout...
18th Aug 2016, 6:07 AM
Tamas Szekffy
Tamas Szekffy - avatar