aspose file tools
The moose likes Beginning Java and the fly likes What is 5++ *5 =? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "What is 5++ *5 =?" Watch "What is 5++ *5 =?" New topic
Author

What is 5++ *5 =?

Ruchi Joshi
Greenhorn

Joined: Dec 22, 2009
Posts: 1
What is the output of following??

public int do(int x) { return (x++) *x ; }

from main :

do(5);

is it 25 or 30?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35220
    
    7
What was the output when you ran it?


Android appsImageJ pluginsJava web charts
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 125
Ruchy, Its compilation error. Are you getting something else ?
swapnl patil
Ranch Hand

Joined: Aug 13, 2007
Posts: 80
Hi Ruchi ,

try this & find out the answer.
Its very simple.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
compilation error only because 'do' is a reserved word. the rest is ok.

the output should be 30.

first x++ evaluates to 5, then x is incremented and then multiplied with itself (6).


JDBCSupport - An easy to use, light-weight JDBC framework -
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 125
Check your private message.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
xsunil kumar wrote:Check your private message.
Please don't send answers to questions by private message or e-mail.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What is 5++ *5 =?
 
Similar Threads
How many objects created for array init
Java loops- linear/log time- calculation
How tricky are the questions
Static??
Operator Question