Using Conditional Expressions.

This is a discussion on Using Conditional Expressions. within the C Programming forums, part of the General Programming Boards category; Is it possible to convert this if statement into a conditional expression? is it worth it? Code: if(newIndex) s[newIndex-1] = ...

  1. #1
    PLC
    PLC is offline
    Registered User
    Join Date
    Sep 2003
    Posts
    7

    Using Conditional Expressions.

    Is it possible to convert this if statement into a conditional expression? is it worth it?

    Code:
     
        if(newIndex)
            s[newIndex-1] = '\0';
            
        else
            s[newIndex] = '\0';
    thx.

  2. #2
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    Code:
    s[newIndex ? newIndex-1 : newIndex] = '\0';
    It's up to you to determine if that's readable enough to be worth the savings.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack that evaluates postfix expressions
    By killmequick in forum C Programming
    Replies: 7
    Last Post: 10-01-2008, 07:23 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Regular expressions [Boost]
    By Desolation in forum C++ Programming
    Replies: 8
    Last Post: 12-30-2006, 10:10 PM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  5. Help please: regular expressions in C++
    By reivaj7999 in forum C++ Programming
    Replies: 3
    Last Post: 08-24-2005, 02:11 AM

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