+ 1
Prefix & Postfix Increment operators
#include <iostream> using namespace std; int main() { int a=3,b=2; b=a++; //after this value of b will be 4 cout<<++b; //here the value getting printed should be 5 but the output is 4 return 0; }
1 Resposta
0
Great example to explain the difference of prefix and postfix increment!
b = a++ will assign the value of a to b and then increment a. So b will be 3, but a will be 4.
cout << ++b will first increment b and then print its new value: 4.