Presentation on theme: "Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands."— Presentation transcript:
Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands. C operators are categorized to several types: assignment operator assignment operator mathematical operators mathematical operators relational operators relational operators logical operators logical operators
Assignment Operator The assignment operator which is the equal sign ( = ). If you write c = y in a C program, the value of y is assigned to c. In assigning, the right side can be any expression and the left side must be a variable name.
Mathematical Operators C mathematical operators can be classified into two: unary and binary Binary operators Mathematical operators perform math operations such as: addition ( + ), subtraction ( - ), multiplication ( * ), division ( / ) and modulus ( % ). addition ( + ), subtraction ( - ), multiplication ( * ), division ( / ) and modulus ( % ).
Mathematical Operators Unary operators C has two unary operators: the increment and the decrement Prefix or infix = ++x for increment and - - x for decrement Postfix = x++ for increment and X - - for decrement
Operator Precedence An expression contains more than one operator. The order in which operations are performed pose a significance. This order is called operator precedence. Operations with higher precedence are performed first when an expression is evaluated. Operators Relative Precedence Operators Relative Precedence ++ - -1 * / %2 + -3
If an expression contains more than one operator with the same precedence level, the operators are performed in left to right order as they appear in the expression. C also uses parentheses to modify the evaluation order. A sub expression enclosed in parentheses is evaluated first without regard to operator precedence.
Relational Operators OperatorSymbolExample Equal==X==A Not equal !=A!=0 Less than y>10 Less than or equal to <=X<=20 Greater than or equal to >=Y>=100
Your consent to our cookies if you continue to use this website.