Thread: comparison operators

  1. #1
    mrukok
    Guest

    comparison operators

    can you use the comparison operators in a long chain in the same way as the assignment operator?, like so:
    Code:
    if(varA == varB == varC)
    //do whatever
    to mean 'if all 3 variables have the same value'.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>to mean 'if all 3 variables have the same value'
    No.

    if (varA == varB && varB == varC)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    NO (Did you try it?)

    But you and use AND & OR:

    if((varA == varB) && (varB == varC)) // AND

    if((varA == varB) || (varB == varC)) // OR

    You CAN "chain" several ANDs or OR's together.

    [EDIT]
    Oops. Had a bitwise operators
    Last edited by DougDbug; 03-24-2003 at 06:00 PM.

  4. #4
    mrukok
    Guest
    ok thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 07:17 AM
  3. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  4. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 04:37 AM
  5. logical operators
    By sballew in forum C Programming
    Replies: 4
    Last Post: 09-04-2001, 06:24 PM