• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Whats the answer FFT how?

 
Ranch Hand
Posts: 55
Mac OS X Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

source:http://www.danchisholm.net/oct1/mybook/chapter3/exam1.html

[ disabled smilies in code and added code tags - Jim ]
[ October 31, 2007: Message edited by: Jim Yingst ]
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yogaraj,

In case you don't already know, the ternary conditional operator ( ? : ) is basically a shorthand for an assignment based on a if-else construct. For instance,

is behaviorally equivalent to

where condition is a boolean expression and v1, v2 have types that are assignable to a. Also, v1 is evaluated only if condition is true, and v2 is evaluated only if condition is false. The main advantages of the ?: operator are that (a) it's often more concise than the equivalent if-else construct; and (b) it's not limited to assignment statements, and can be used within another expression (as your example illustrates).

Another thing to realize is that the ?: operator is right-associative, like the assignment operator (=) but unlike the usual arithmetic operators. What this means is that "c ? v1 : c2 ? v2 : v3" is equivalent to "c ? v1 : (c2 ? v2 : v3)" and not "(c ? v1 : c2) ? v2 : v3".

The above should be all you need to figure out why your code produces the output you see. Good luck!
[ October 31, 2007: Message edited by: Kelvin Lim ]
 
We don't have time for this. We've gotta save the moon! Or check this out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic