Thread: What is this?

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Virginia Beach, Virginia
    Posts
    7
    Rep Power
    0

    Question What is this?


    Where can I find documentation for the folllowing code. I know all about argv and argc. What is the "(x) ? x : x" part?

    (i < argc-1) ? " " : ""

    I've also seen integers used in place the chars as well.

    Anyone?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    NC, USA
    Posts
    364
    Rep Power
    13
    It's a conditional expression.

    expr1 ? expr2 : expr3

    expression expr1 is evaluated first. If it's true then expr2 is evaluated and if it's not then expr3 is evaluated.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Virginia Beach, Virginia
    Posts
    7
    Rep Power
    0

    Ahhhh.


    So its short hand for an if..else basically.
  6. #4
  7. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    Well, sort of. But an if-else construct is a statement, whereas the ternary ?: operator results in an expression. Example:

    a = (x < y) ? x : y;

    So yes, it's like an if-else statement in the sense that there's a conditional expression involved, but that's about it.
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/

IMN logo majestic logo threadwatch logo seochat tools logo