• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

Don't understand this output from statement

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

One of my recent programming exams had this question.




The options were, 5 5, 10 10, 5 10, 10 5.

I chose 5 10, but surprisingly the answer is 10 10 upon running the code, which is beyond me... Could somebody explain why is that?

Regards!
 
Rancher
Posts: 494
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Samantha

If you have an expression (exp1, exp2) then yes, both exp1 and exp2 are evaluated. But the value of exp1 is thrown away; the result of (exp1, exp2) is exp2. Does that help?

Cheers
John
 
Samantha Will
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Matthews wrote:Hi Samantha

If you have an expression (exp1, exp2) then yes, both exp1 and exp2 are evaluated. But the value of exp1 is thrown away; the result of (exp1, exp2) is exp2. Does that help?

Cheers
John



Thanks a lot... I've been thinking hard just to make sense of it...
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic