Download presentation

Presentation is loading. Please wait.

Published bySamuel Hahn Modified over 4 years ago

1
Operators and Arithmetic Operations

2
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

3
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.

4
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 ( % ).

5
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

6
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

7
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.

8
Relational Operators OperatorSymbolExample Equal==X==A Not equal !=A!=0 Less than <X<0 Greater than >y>10 Less than or equal to <=X<=20 Greater than or equal to >=Y>=100

9
Logical Operators OperatorSymbolExample and&& var1 & & var2 or|| var1 | | var2 not!!var1

Similar presentations

OK

Data Types Declarations Expressions Data storage C++ Basics.

Data Types Declarations Expressions Data storage C++ Basics.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google