Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • 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: 317
11
  • 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...
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic