Академический Документы
Профессиональный Документы
Культура Документы
Session Objectives
Explain Assignment Operator
Introduction
C supports 4 types of operators -
Arithmetic
Logical
Relational
Bitwise
Multiple Assignment
Many variables can be assigned the same value in a single statement.
Arithmetic Operators
Arithmetic Operators are used to perform numerical operations They are divided into 2 classes :
Binary Operators
The following example shows all the binary operators used in C
Unary Operators
a = a + 1; can also be written as a++; a pls = +50 as a--; a= = -75; a - 1; can also be written
Arithmetic Expressions
Mathematical expressions can be expressed in C using arithmetic operators
Examples
Precedence Of Operators
Precedence establishes the hierarchy of one set of operators over another when an arithmetic expression is to be evaluated. It refers to the order in which C evaluates operators. The precedence of the operators can be altered by enclosing the expressions in parentheses
Type Conversion
The automatic type conversions for evaluating an expression are given below -
For example,
The purpose of the above statement is to assign the value of num1 or num2, whichever is larger, to the variable max. First the condition (num1>num2) is evaluated. If it is true, the value num1 is assigned to max, else num2 is assigned to max
First b is assigned the value 5 and then a is assigned the value 7. The parentheses are necessary because the comma operator has a lower precedence than the assignment operator
Linux, C, C++ / Programming with C / Session 2 / 15 of 17
C Shorthand
Can be written as
Can be written as