0
find mistake
perform in c++ int i=2; cout<<i++<<i<<i++<<i; cout<<i; answer is 33224
10 Antworten
+ 3
1)Firstly You should know about pre increment and post increment,
Lets say we have p = count++; and int count =5
p = 5(p gets the value of count only, not the ++ part) and count = count+1;
so count becomes 6. To know more about this watch this video: https://www.youtube.com/watch?v=FkxFPJG5paw
2)Coming to your question firstly i dont think that is the correct answer. I tried running your program on Dev c++ and the output was absurd.
BTW if you want to know how to debug, watch this video
https://www.youtube.com/watch?v=LqvLGx8I9QA
3)Without debugging i got 34244 and with debugging I got 23344 which must be the correct one.
Break your code in this manner and use the pre and post increment concept
#include<iostream>
using namespace std;
int main()
{
int i=2;
cout<<i++; // lets say x = i++, now x = i(2); so 2 will be displayed
cout<<i; // i will be i++ or i+1; so new value of i is 3
cout<<i++; // as new value of i is 3, again let y = i++, so y = i(3)
cout<<i; // i will be incremented so i =i+1 ;new value of i is 4
cout<<i; //whether we cout << i or cout<<i++ the output will be the same i.e4
return 0;
}
+ 1
you want to get answer as 33224? or you want to get answer as per that code?
+ 1
The actual answer is 34244. you want to know how we get that answer?
+ 1
Please give me a couple of minutes. I shall explain it in a simpler manner.
+ 1
np :)
0
no according to that code my answer comes this but it should not come this...
0
yep
0
actually situation is that... in my question paper above code was given and this answer was stated as correct..also turbo CPP gives the same answer..how could it be
0
OK bro
0
thx