Mini If

This is a discussion on Mini If within the C Programming forums, part of the General Programming Boards category; Can i do this in C? (i < 0) ? i = 1 : NULL;...

  1. #1
    Banned
    Join Date
    Mar 2008
    Posts
    78

    Mini If

    Can i do this in C?

    (i < 0) ? i = 1 : NULL;

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Of course.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    And it's called a ternary operator

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    Quote Originally Posted by Milhas View Post
    Can i do this in C?
    Yes, but I'd do it this way:

    Code:
    i = (i < 0) ? 1 : i;
    But why bother when you can:

    Code:
    if(i < 0) i = 1;

  5. #5
    Banned
    Join Date
    Mar 2008
    Posts
    78
    Nice! Thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new Opera mini - web browser for any java enabled mobile
    By xErath in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-29-2006, 03:23 PM
  2. Binary Trees MINI MAXING, probability trees
    By curlious in forum General AI Programming
    Replies: 3
    Last Post: 09-30-2005, 10:57 AM
  3. New Mini Project
    By jverkoey in forum Game Programming
    Replies: 3
    Last Post: 05-12-2004, 11:00 PM
  4. Problem with my mini project
    By supz in forum C++ Programming
    Replies: 0
    Last Post: 04-12-2003, 11:30 AM
  5. Does anybody have a mini compiler can be reused?
    By jiabin in forum C Programming
    Replies: 1
    Last Post: 08-29-2001, 09:50 AM

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