• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

What is 5++ *5 =?

 
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?
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the output when you ran it?
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruchy, Its compilation error. Are you getting something else ?
 
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.
 
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: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your private message.
 
Marshal
Posts: 64662
225
  • 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
Boost this thread!