"?" and ":"

This is a discussion on "?" and ":" within the C Programming forums, part of the General Programming Boards category; I was wondering what the "?" and ":" do when in code like this Code: 12 ? 3 : 20 ...

  1. #1
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790

    "?" and ":"

    I was wondering what the "?" and ":" do when in code like this

    Code:
    12 ? 3 : 20
    what does the "?" and ":" do in the previous code. I know its probably somewhere, but I am having trouble finding the answer.
    Thanks in advance.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    It will be true the result (Different of 0) cuz 12 is a number different of zero.

    Code:
    (condition) ? (do this if true) : (do this if false);

  3. #3
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    thanks, I could of sworn it had something to do with TRUE or FALSE.

  4. #4
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    A more accurate definition of what it does would probably be the whole expression becomes instead of do this

    e.g.
    Code:
    int x;
    bool y=true;
    x=y?3+3:cout<<"This won't execute";
    I AM WINNER!!!1!111oneoneomne

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Panopticon

    e.g.
    Code:
    int x;
    bool y=true;
    x=y?3+3:cout<<"This won't execute";
    Of course it won't execute. That's C++ and this is a C board...

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    LoL! damn.. Habitual error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Use of "?" ":"
    By MK27 in forum C Programming
    Replies: 6
    Last Post: 12-03-2008, 02:21 AM
  2. What does "{}" mean in C++?
    By meili100 in forum C++ Programming
    Replies: 11
    Last Post: 01-04-2008, 04:41 PM
  3. What does these lines do after ":" mark?
    By asilter in forum C++ Programming
    Replies: 7
    Last Post: 09-27-2007, 07:31 AM
  4. parse error before "{" token
    By getout in forum C Programming
    Replies: 4
    Last Post: 12-31-2006, 12:26 PM
  5. Replies: 3
    Last Post: 11-11-2003, 02:44 AM

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