Boolean operators returns true or false All these operators associate left to

Boolean operators returns true or false all these

This preview shows page 7 - 8 out of 8 pages.

Boolean operators returns true or false . All these operators associate left-to-right, with ! having higher precedence than any binary operator, && having lower precedence than the relational operators, and higher precedence than || , and || having higher precedence than the assignment operators. Evaluation stops as soon as possible. Hence both expressions below would evaluate to true , with no division by zero being performed. !(2 == 3 && 1 / 0 == 3); 2 == 2 || 1 / 0 == 3; COMP9021 (Principles of Programming) Notes 6.0: Variables, assignments, operators 2014 session 1 26 / 29 Bitwise operators There are 3 bitwise operators: the unary ~ for bitwise negation , and the binary | , & , ^ , << and >> for bitwise disjunction , bitwise conjunction , bitwise xor , left shift and right shift , respectively. All these operators associate left-to-right, with ! having higher precedence than any binary operator, & having lower precedence than the relational operators, and higher precedence than ^ , ^ having higher precedence than | , and | having higher precedence than the boolean operators. The program bits.c illustrates. COMP9021 (Principles of Programming) Notes 6.0: Variables, assignments, operators 2014 session 1 27 / 29 More on assignment operators Also referred to as assignment operators, += , -= , *= , /= , %= , &= , ^= , |= , <<= and >>= are abbreviations for assigning to the variable on the left hand side of the operator the result of applying that operator to the current value of that variable and to the name of a data item provided on the right hand side of the = sign. For instance, x *= 3 * y + 12 is an abbreviation for x = x * (3 * y + 12) The abbreviated forms are more compact and may produce more efficient machine code than their longer counterparts. Assignment operators associate right-to-left. For (a bad) example, int a = 2, b; a += b = 1; would assign 3 to a (a side effect of the 2nd expression being evaluated to 3) . COMP9021 (Principles of Programming) Notes 6.0: Variables, assignments, operators 2014 session 1 28 / 29
Image of page 7

Subscribe to view the full document.

Macros for some operators The iso646.h header file defines the following macros for alternative denotations of some inequality operator, the boolean operator, and some bitwise and assignment operators. not_eq for != not for ! or for || and for && compl for ~ bitor for | bitand for & bitxor for ^ or_eq for |= and_eq for &= xor_eq for ^= COMP9021 (Principles of Programming) Notes 6.0: Variables, assignments, operators 2014 session 1 29 / 29
Image of page 8
  • Fall '19
  • 11

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes