GeekInterview.com
Home
Tech Articles
Code Samples
Learn
Freelance Projects
Online Testing
Geek Talk
Job Postings
Knowledge Base
Geek Blogs
Question Bank
Interview Questions
Certification
Placement Papers
Tech FAQ
Career Advice
Engineering
Ask Question
I am new,
Sign me up!
User Name
Remember Me?
Password
Interview Questions
Certification
Placement Papers
Tech FAQ
Career Advice
Engineering
Ask Question
GeekInterview.com
>
Interview Questions
>
J2EE
>
Core Java
Go To First
|
Previous Question
|
Next Question
Core Java
| Question 468 of 502
Print
What will be the result and why
int i=10;
i=i++;
System.out.println(i);
Total Answers and Comments:
18
Last Update: November 12, 2009 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
,
swpnl_ptl
,
james.vinett
,
bino75
,
sujithkthomas
Sorting Options
Latest First
Oldest First
By Rating
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
0
4
Overall Rating:
-4
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
|
No
4
2
Overall Rating:
+2
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
0
4
Overall Rating:
-4
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
|
No
3
1
Overall Rating:
+2
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
|
No
1
0
Overall 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
|
No
0
2
Overall Rating:
-2
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
|
No
2
2
Overall Rating:
-N/A-
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
0
1
Overall Rating:
-1
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
1
0
Overall Rating:
+1
Page 1 of 2
«
First
1
2
>
Last
»
Go To Top
Sponsored Links
Related Categories
—
Core Java Interview Questions
EJB Interview Questions
Hibernate Interview Questions
Java Interview Questions
Java Patterns Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSP Interview Questions
Java OOPS Interview Questions
Ruby Interview Questions
Servlets Interview Questions
Spring Interview Questions
Struts Interview Questions
Websphere Interview Questions
Sponsored Links
About Us
-
Privacy Policy
-
Terms and Conditions
-
Contact
-
Ask Question
-
Propose Category
-
Site Updates
Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved