Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is 5++ *5 =?

 
Ruchi Joshi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the output when you ran it?
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruchy, Its compilation error. Are you getting something else ?
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ruchi ,

try this & find out the answer.
Its very simple.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your private message.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48946
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xsunil kumar wrote:Check your private message.
Please don't send answers to questions by private message or e-mail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic