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  >  Placement Papers  >  CTS
Go To First  |  Previous Question  |  Next Question 
 CTS  |  Question 74 of 85    Print  
Why Result is Different for
1)
int x=5;
int y;
y=++x + ++x + ++x
2)
int x=5;
int y=++x + ++x + ++x

  
Total Answers and Comments: 3 Last Update: May 30, 2008     Asked by: Prakash 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 23, 2007 09:14:21   #1  
machogamer Member Since: January 2007   Contribution: 3    

RE: Why Result is Different for1)int x=5;
In Type 1: Line 3 is treated as an expression, and based on the " Operator Precedence " the increment [ ++ ] operatortakes precedence over summation [ + ] operator. Hence in the expression, the increment operation is done first, and then the summation operation is done, thus the output of the expression will be " 24 ".In Type 2: Line 2 is treated as an assignment statement, and is hence evaluated from left to right. Thus the value of ' y ' in this case will be 21.
 
Is this answer useful? Yes | No
February 27, 2007 12:47:45   #2  
Remi        

RE: Why Result is Different for1)int x=5;
How does it sum up to 24?
 
Is this answer useful? Yes | No
February 05, 2008 04:15:24   #3  
sauvik_36 Member Since: November 2007   Contribution: 1    

RE: Why Result is Different for1)int x=5;int y;y=++x + ++x + ++x2)int x=5;int y=++x + ++x + ++x
it gives 21 on both cases with javac and 24 on both cases wth turboc....
the result can be erratic there4... varies wth the compiler....

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Related Categories
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