Basic Evaluation Question

This is a discussion on Basic Evaluation Question within the C++ Programming forums, part of the General Programming Boards category; Hi, so my friend gave me this C++ brain teaser, and it's one of those really jumbled up evaluation ones. ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    Basic Evaluation Question

    Hi, so my friend gave me this C++ brain teaser, and it's one of those really jumbled up evaluation ones. It says 0 ? 0 : 1 in it.. Which leads me to ask, what does 0 evaluate too if it's not an actual question like 0<3 or something... Does any single integer evaluate to True because it has nothing to compare it to, so it basically just says if (there is a integer) then do this. Does it evaluate to false because it's a zero and 0 = false? Ok cheers.. Pretty confused lol.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Any x in a boolean context is essentially treated as
    if ( x != 0 )

    The 0 being prompted to 0.0 or NULL as appropriate.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Sorry, but I have no idea what you just said ahah.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Zero is false and anything non-zero is true.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    66
    it's equal as

    Code:
    false? 0 : 1

  6. #6
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Ok cheers
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic math programming question
    By hebali in forum C Programming
    Replies: 38
    Last Post: 02-25-2008, 03:18 PM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 02:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 02:24 AM
  4. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 03:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21