+ 1
can anyone give me solution of this code that why it shows output 6 7 7
#include<iostream>using namespace std;int main(){int i =5;cout<<i++<<++i<<i;return 0;}
5 Respostas
+ 1
1. 5 ---> i++ --> prints 6
2. 6----> ++i--> prints 7
3. 7---->you don't add anything ---> prints 7
Also keep in mind:
The difference is that the post-increment operator i++ returns i as it was before incrementing, and the pre-increment operator ++i returns i as it is after incrementing
0
can you please explain me line by line?
0
Ok. So you have integer int i = 5. Then you have cout<<i++(at this point it takes 5 and adds +1 so it prints 6)<++i(at this point it adds up +1 to 6, so it prints 7)<i;(you don't change here anything. i=7)
0
but in post increment first write the value and then its value increase by 1..so that according my ans is 5 7 7...if i am wrong than correct me
- 1
sorry but i didn't get you