+ 2
i++ and ++i I'm not getting how is this is working in c
#include<stdio.h> int main () { int i=10; printf("%d%d%d",i,++i,i++); return o; } output : 10 12 12 how????????
21 Antworten
+ 18
I hope it sort out everything,
https://code.sololearn.com/cjHQRJUG5NTf/?ref=app
+ 16
Zameer, wait for a while...
+ 6
I tried it and was shocked, output is 121210.
https://code.sololearn.com/c4r1k93b5GkA/?ref=app
+ 5
But in Java, it shows 101111.
https://code.sololearn.com/cYLrBTXusch4/?ref=app
+ 5
That always show result like that surely.....
Must be...
Integer i = 10;
String a = String.format("%d%d%d",i,++i,i++);
System.out.print(a);
To make more sense.....
+ 4
No...
It's 12 12 10.....
Because of......Dunno. we ever talk about this and not get answer yet :P
+ 4
#include <iostream>
using namespace std;
int main(){
int i=10;
cout << i << ++i << i++;
//This one too -_-....
}
+ 4
10 12 12?
Where did you get that result?
+ 4
From http://stackoverflow.com/questions/33445796/increment-and-decrement-with-cout-in-c
"Please notice that cout << x++ << ++x; is just another notation for:
operator<<( operator<< (cout, x++), ++x);
The order in which your x++ and ++x statements are evaluated is undefined, so is the effect of your code.
Even if it seems to happens from right to left in your particular examples, you should not rely on that by any means.
Just make another experiment by using multiple statements as:
cout << ++x << " ";
cout << x++ << " ";
cout << x++ << endl;
The solution to your problem is:
Never write code which results in undefined behaviour! :)"
+ 2
it was question from one of the best company during interview
+ 2
in c++ also
#include <iostream>
using namespace std;
int main() {
int i=10;
cout<<i;
cout<<++i;
cout<<i++;
return 0;
}
output is 10 11 11
+ 1
Output is 10 11 11
+ 1
Maybe due to the way printf handles arguments.
+ 1
ok
0
no its 10 12 12
0
I'm getting 10 12 12 as op
0
yes 10 12 12 or 12 12 10 as output
how?????
0
I also checked in c,c++ and java getting same ans as 12 12 10
0
I assumed that ll like this 10 12 12 but the op is 12 12 12 10
I'm getting confused