Operators Expressions And Assignment Statements Chapter 4 What















![Operator Precedence Chart Associativi ty left-toright Operator Type Operator Primary Expression Operators () []. Operator Precedence Chart Associativi ty left-toright Operator Type Operator Primary Expression Operators () [].](https://slidetodoc.com/presentation_image_h2/1e66eb7ade1685e015f34cb8472f4a5b/image-16.jpg)



- Slides: 19
Operators, Expressions And Assignment Statements Chapter 4
What is an Operator? • It is a symbol which represents a particular operations that can be performed on some data. • The data itself is called the ‘operand’. • The operator thus operates on an operand. • Example : 4 + 2 -3 • The symbol + and – are operators and the constants 4, 2 and 3 are operands.
Operators Types • Operators are C’s forte. – Arithmetic – Increment and Decrement – Modulo Division – Relational – Logical – Bitwise – Conditional – Assignment
Arithmetic Operators • • Plus Minus Division Multiplication - + / *
Increment and Decrement • C offers two special operators ++ and – called increment and decrement operators. • Types – Pre • + + i (Pre-Increment) • - - i (Pre-Decrement) – Post • i + + (Post-Increment) • i - - (Post-Decrement)
Modulo Division Operator • C Provides one more binary arithmetic operator % called Modulo Division operator. • This operator is a supplement to the division operator.
Relational Operator • These operators are used to compare two operands to see whether they are equal to each other, unequal, or whether one is gre 3 ater than the other. • < (less than) • > (greater than) • <= (less than equal to) • >= (greater than equal to) • == (equal to) • != (not equal to)
Logical Operators • Logical operators are useful when we want to test multiple conditions. • There are 3 types of logical operators and they work the same way as the boolean AND, OR and NOT operators. • && - Logical AND – All the conditions must be true for the whole expression to be true. – Example: if (a == 10 && b == 9 && d == 1) means the if statement is only true when a == 10 and b == 9 and d == 1.
Logical Operators cont… • || - Logical OR – The truth of one condition is enough to make the whole expression true. – Example: if (a == 10 || b == 9 || d == 1) means the if statement is true when either one of a, b or d has the right value. • ! - Logical NOT (also called logical negation) – Reverse the meaning of a condition – Example: if (!(points > 90)) means if points not bigger than 90.
Bitwise Operators • One of C’s powerful features is a set of bit manipulation operators. • These permit the programmer to access and manipulate individual bits within a piece of data. • The various Bitwise operators available in C – – – ~ ( one’s complement) >> (right sift) << (left shift) & (Bitwise AND) | (Bitwise OR) ^ (Bitwise XOR)
Bitwise Operators
Conditional Operator • The conditional operator ? and : are sometimes called ternary operators since they take three operands. • Syntax: expression 1 ? expression 2 : expression 3 • Explanation : • If expression 1 is true, then the value returned will be expression 2 otherwise the value return will be expression 3.
The Comma Operator • The comma operator(, ) permits two different expressions to appear in situations where only one expression would ordinarily be used.
sizeof Operator • The sizeof operator returns the number of bytes the operand occupies in memory. • The operand may be a variable, a constant or a data type qualifier.
Precedence Of Operators
Operator Precedence Chart Associativi ty left-toright Operator Type Operator Primary Expression Operators () []. -> expr++ expr-- Unary Operators * & + - ! ~ ++expr -expr (typecast) sizeof right-toleft Binary Operators */% +>> << < > <= >= == != & ^ | && || left-toright Ternary Operator ? : Assignment Operators Comma right-toleft = += -= *= /= %= >>= <<= &= ^= right-to|= left-to, right
Type Conversion
Assignment Statements • These statements are used to assign the value to a variable. • Syntax; Variable = expression
Thank U End Chapter 4