tailieunhanh - Session 3

| Operators and Expressions Session 3 Operators and Expression Objectives Explain Assignment Operator Understand Arithmetic Expressions Explain Relational and Logical Operators Understand Bitwise logical operators and expressions Explain casts Understand Precedence of Operators Elementary Programming with C/Session 3/ of 25 Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators Elementary Programming with C/Session 3/ of 25 The Assignment Operator variable_name = expression; lvalue rvalue Assignment operator The assignment operator(=) can be used with any valid C expression (Left value) (Right value) Elementary Programming with C/Session 3/ of 25 Multiple Assignment Many variables can be assigned the same value in a single statement a = b = c = 10; However, you cannot do this : int a = int b = int b = int c = 10 X Elementary Programming with C/Session 3/ of 25 Operators 4 Types Arithmetic Relational Logical Bitwise Elementary Programming with C/Session 3/ of 25 Arithmetic Expressions Mathematical expressions can be expressed in C using arithmetic operators Examples a * (b + c/d)22 ++i % 7 5 + (c = 3 + 8) Elementary Programming with C/Session 3/ of 25 Relational & Logical Operators-1 Test the relationship between two variables, or between a variable and a constant Used to Relational Operators Elementary Programming with C/Session 3/ of 25 Logical operators are symbols that are used to combine or negate expressions containing relational operators Relational & Logical Operators-2 Expressions that use logical operators return zero for false, and 1 for true Example: if (a>10) && (a Elementary Programming with C/Session 3/ of 25 Bitwise Logical Operators-1 Processes data after converting number to its binary equivalent. (Bit wise representation) AND ( NUM1 & NUM2) Return 1 if both the operands are 1 OR ( NUM1 | NUM2 ) Returns 1 if bits of either of the operand are 1 NOT ( ~ NUM1) Reverses the bits of | Operators and Expressions Session 3 Operators and Expression Objectives Explain Assignment Operator Understand Arithmetic Expressions Explain Relational and Logical Operators Understand Bitwise logical operators and expressions Explain casts Understand Precedence of Operators Elementary Programming with C/Session 3/ of 25 Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators Elementary Programming with C/Session 3/ of 25 The Assignment Operator variable_name = expression; lvalue rvalue Assignment operator The assignment operator(=) can be used with any valid C expression (Left value) (Right value) Elementary Programming with C/Session 3/ of 25 Multiple Assignment Many variables can be assigned the same value in a single statement a = b = c = 10; However, you cannot do this : int a = int b = int b = int c = 10 X Elementary Programming with C/Session 3/ of 25 Operators 4 Types Arithmetic Relational Logical Bitwise Elementary .

TỪ KHÓA LIÊN QUAN