GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 468 of 493    Print  
What will be the result and why
int i=10;
i=i++;
System.out.println(i);



  
Total Answers and Comments: 14 Last Update: July 14, 2008     Asked by: Arnab.infinity 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: fcasttro
 

10 Only. Since this is post increment Operator



Above answer was rated as good by the following members:
getravi2k, praspasr2
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
March 19, 2008 07:02:39   #1  
swa_jag Member Since: March 2008   Contribution: 1    

RE: What will be the result and why
eleven
 
Is this answer useful? Yes | No
March 21, 2008 08:18:39   #2  
fcasttro Member Since: March 2007   Contribution: 16    

RE: What will be the result and why

10 Only. Since this is post increment Operator


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
March 24, 2008 10:09:56   #3  
subbaraju.p Member Since: March 2008   Contribution: 1    

RE: What will be the result and why
eleven, as "i" will be updated before the system.out.print statement executes.
 
Is this answer useful? Yes | No
April 01, 2008 04:01:27   #4  
poonamjava Member Since: December 2006   Contribution: 20    

RE: What will be the result and why
value of i will be 10
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 01, 2008 04:17:29   #5  
poonamjava Member Since: December 2006   Contribution: 20    

RE: What will be the result and why
i will be 10

because i=i++;
if u break it
i=i; //1 step
here we are assigned the value and same variable.

if u r taking some other variable like j
j=i++

now print System.out.print(i+"     "+j)
Ans:

i=11
j=10


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
April 01, 2008 04:17:49   #6  
nadhem Member Since: March 2008   Contribution: 1    

RE: What will be the result and why
value will be 10,

the value is affected before being evaluated,

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 16, 2008 05:01:11   #7  
kolli.Dedeepya Member Since: April 2008   Contribution: 1    

RE: What will be the result and why
10 because i will be first assigned and then incremented
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 16, 2008 08:24:39   #8  
redleader Member Since: April 2008   Contribution: 10    

RE: What will be the result and why
In C++ and other languages the answer will be 11

Somehow it is 1=10. What should be noted is that i never gets incremented to 11.

int i=10;i=i++;System.out.println(i);

should not be logically different from

int i=10;
i=i;
i++;
System.out.println(i);

but in java somehow, it is logically different.

Post increment never occurs, or occurs but is discarded!!!!!!!!!!!!!!!!!!!!
This is a fundamental flaw in basic arithmatic in java!!!!!!!!!

 
Is this answer useful? Yes | No
April 16, 2008 08:25:43   #9  
redleader Member Since: April 2008   Contribution: 10    

RE: What will be the result and why

on second line 1=10 should be i=10, for those who didnt know.


 
Is this answer useful? Yes | No
May 02, 2008 02:46:49   #10  
kishorpatil85 Member Since: April 2008   Contribution: 1    

RE: What will be the result and why
i will be 10 bcoz of associativity it just ignores post increament operator,
but it will work for pre-increament

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape