int i=10;printf("%d%d%d",i,i++,++i);

compiler dependent

Showing Answers 1 - 37 of 37 Answers

Harry

  • Aug 12th, 2005
 

10 12 12

  Was this answer useful?  Yes

naveen

  • Jan 21st, 2006
 

11 11 11 is the answer :-|

  Was this answer useful?  Yes

Pradeep Singh MCA , 6th Sem , CUSAT

  • Feb 11th, 2006
 

The answer will be : 12 11 11

Vishal Pratap Singh

  • Feb 22nd, 2006
 

Answer:12,11,11   As we know that it calculate the value of i from right to left and print the value from left to right.so in this question first the value of i becomes 11 then again in post incremet  the value of i become 11 and at last when post increment increase the value of 11 to 12 .then it print 12,11,11

Scott

  • Apr 2nd, 2006
 

Guys...this IS the answer since I ran it through...10 10 12I knew this one was worth actually doing, since I remember when learning programming 101 years ago that i++ will use the current value for i AND THEN increment it. ++i takes the current value (which is now 11) and adds one more to that BEFORE using it. That is why you get the above output. int i=10; int[] bob = new int[3]; bob[0]=i; bob[1]=i++; bob[2]=++i; for(int j=0;j

manmohan

  • Apr 8th, 2006
 

the answer is : 12,11,12

  Was this answer useful?  Yes

sanjay

  • Apr 22nd, 2006
 

12 12 12

  Was this answer useful?  Yes

shrabani

  • Apr 24th, 2006
 

Hi,

The answer should be 10,10,12.....

first it will take i as 10 then i++ will first take the value then it will do the increment so it will print 10 .now the value of i=11 so ++i will print as 12.

So the answer is 10 10 12.

But still it depends upon the C compiler. The answer is correct as per the book.

vicky

  • Jun 8th, 2006
 

10 12 10

  Was this answer useful?  Yes

vicky

  • Jun 8th, 2006
 

    10 12 10

  Was this answer useful?  Yes

darshan

  • Jun 27th, 2006
 

The answer is 12 11 11.But actually its an undefined behaviour and it depends on the compiler.

  Was this answer useful?  Yes

rajendra

  • Jul 7th, 2006
 

Output 121111 it is compiler dependent. But in TC arguments are passed from right to left in function hence 121111 is correct ans...

  Was this answer useful?  Yes

Nancy

  • Sep 8th, 2006
 

  10 10 12

  Was this answer useful?  Yes

UMTopSpinC7

  • Oct 8th, 2006
 

g++ says it is 12, 11, 12... it sounds like it is compiler dependant though... wish i had an explanation other than that though.

  Was this answer useful?  Yes

lily

  • Dec 4th, 2006
 

The output will be 10,10,12

  Was this answer useful?  Yes

swetha

  • Feb 15th, 2007
 

THE ANSWER IS 12 11 11

  Was this answer useful?  Yes

Chandnal

  • Mar 22nd, 2007
 

The output will be 10,10,12.

  Was this answer useful?  Yes

sujithag

  • Nov 18th, 2008
 

Compiler dependent.
The output is obtained based on how the compiler traverse from left to right or right to left.

  Was this answer useful?  Yes

satyam131

  • May 14th, 2010
 

12 11 11

Because one time a variable can contain only one value, and printf is right associative so first of all ++i will executed i.e 11, then i++ i.e. 11 and then i that will be 12.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions