+ 2

Output of the following code:

#include<stdio.h> int main() { int i =5; printf("%d%d%d", i, i++, ++i) ; }

18th Apr 2017, 4:06 AM
Aman Gupta
Aman Gupta - avatar
7 Respuestas
+ 12
@Nawaj Shareef, then how do you explain: char ch = 'A'; int ni = 89; printf("Character = %c, Number = %d\n", ch, ni); ?????? It doesn't work right to left, the va_args of printf are left to right. Edit: and anyways, the outcome like OP says, is 767 which still doesn't explain, even with your right to left theory, why the number would decline by one in the middle and return to 7 afterwards.
18th Apr 2017, 1:53 PM
SoraKatadzuma
SoraKatadzuma - avatar
+ 8
I don't know the answer but plz give a like to my code so I can get a badge
18th Apr 2017, 4:42 AM
arpit dixit
arpit dixit - avatar
+ 6
pretty sure its 557 unless some sorcery is going on there
18th Apr 2017, 4:23 AM
Edward
+ 6
it should be giving you 557. Why? because the initial call to I is 5. the next call (i++) is post-increment to which means it will still be 5 until after it's use in this instance. The last call to i (++i) is a pre-increment call which means the now 6 valued i will become 7 before it's use giving you 557. I don't know what else you're doing to it but 557 is what you should be getting.
18th Apr 2017, 11:07 AM
SoraKatadzuma
SoraKatadzuma - avatar
+ 5
The output of your code depends upon the compiler being used for compiler - GCC is giving the output 767 - Turbo C++ is giving output 766
18th Apr 2017, 5:35 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 3
well i never used c++. didnt know it compiled differently. at least in java the answer would be 557
18th Apr 2017, 3:19 PM
Edward
+ 1
That's not the correct answer. It gives 767. I need to know how does this happen
18th Apr 2017, 4:12 AM
Aman Gupta
Aman Gupta - avatar