Help with what a line does

This is a discussion on Help with what a line does within the C++ Programming forums, part of the General Programming Boards category; Can anyone tell me what the code num1 = (a >= b ? a : b); does? Specifically the "?" ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    31

    Help with what a line does

    Can anyone tell me what the code num1 = (a >= b ? a : b); does?
    Specifically the "?" and the ":"

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Re: Help with what a line does

    Originally posted by Aakash Datt
    Can anyone tell me what the code num1 = (a >= b ? a : b); does?
    Specifically the "?" and the ":"
    Ternary operator. That statement is equivalent to:
    Code:
    if (a >= b)
       num1 = a;
    else 
       num1 = b;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 11:01 AM
  2. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-19-2009, 12:44 AM
  3. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  4. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  5. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 06:44 PM

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