Thread: Help with what a line does

  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-18-2009, 11:44 PM
  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, 05:44 PM