SlideShare a Scribd company logo
1 of 22
Download to read offline
OPERATORS & EXPRESSIONS
An operator is a symbol (+,-,*,/)that tells the
compiler to perform specific mathematical or logical
manipulations. C language is rich in built-in
operators and provides the following types of
operators:
Operators in C
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
Arithmetic operators
Operator example Meaning
+ a + b Addition –unary
- a – b Subtraction- unary
* a * b Multiplication
/ a / b Division
% a % b Modulo division- remainder
Compound Assignment Operator
●
Often we use “update” forms of operators
– x=x+1, x=x*2, ...
●
C offers a short form for this:
– Generic Form
variable op= expr equivalent to variable = variable op expr
Update forms have value equal to the final value of expr
●
i.e., x=3; y= (x+=3); /* x and y both get value 6 */
Operator Equivalent to:
x *= y x = x * y
y -= z + 1 y = y - (z + 1)
a /= b a = a / b
x += y / 8 x = x + (y / 8)
y %= 3 y = y % 3
Comma Operator has Lowest Precedence i.e it is having
lowest priority so it is evaluated at last.
Comma operator returns the value of the rightmost operand
when multiple comma operators are used inside an
expression.
Comma Operator Can acts as –
Operator : In the Expression
Separator : Declaring Variable , In Function Call
Parameter List
Comma Operators
Let a=5 and b=10
a++; //a becomes 6
a--; //a becomes 5
++b; //a becomes 11
--b; //a becomes 9
Program for pre­increment &post­increment
#include<stdio.h> Output :
void main() Value of a : 10
{ Value of b : 11
int a,b,x=10,y=10;
a = x++;
b = ++y;
printf("Value of a : %d",a);
printf("Value of b : %d",b);
}
PRE­INCREMENT & POST INCREMENT
Relational
Operator
Meaning
> Greater than
>= Greater than or
equal to
<= Less than or
equal to
< Less than
== Is equal to
!= Is not equal to
Logical
Operator
Name of the
Operator
&& And Operator
| Or Operator
! Not Operator
Operators
Examples
Truth Table
a b Value of the
expression
a&&
b
a || b
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
Shorthand Assignment operators
Simple assignment
operator
Shorthand
operator
a = a+1 a + =1
a = a-1 a - =1
a = a* (m+n) a * = m+n
a = a / (m+n) a / = m+n
a = a %b a %=b
Conditional Operators [ ?: ] :
Ternary Operator Statement in C
expression 1 ? expression 2 : expression 3
where
expression1 is Condition
expression2 is Statement Followed if Condition is True
expression2 is Statement Followed if Condition is False
BITWISE OPERATORS
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive
OR
<< Shift left
>> Shift right
These operators allow manipulation of data at the bit level
Review – Bitwise Operations in
Integers
• & – AND
●
Result is 1 if both
operand bits are 1
• | – OR
●
Result is 1 if either
operand bit is 1
• ^ – Exclusive OR
●
Result is 1 if operand
bits are different
• ~ – Complement
●
Each bit is reversed
• << – Shift left
●
Multiply by 2
• >> – Shift right
●
Divide by 2
Corresponding bits of both operands are combined by the
usual logic operations.
Apply to all kinds of integer types:–
Signed and unsigned
char, short, int, long, long long
Assume if A = 60; and B = 13; now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
---------------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The Bitwise operators supported by C language are listed in the following
table. Assume variable A holds 60 and variable B holds 13, then:
Example for Bitwise Operations
Special operators
1. Comma operator ( ,)
2. sizeof operator – sizeof( )
3. Pointer operators – ( & and *)
4. Member selection operators – ( . and ->)
● BODMAS RULE- Brackets of Division Multiplication Addition
Subtraction
PRECEDENCE OF OPERATORS
Brackets will have the highest precedence and have to be evaluated
first, then comes of , then comes division, multiplication,addition and
finally subtraction.
The 2 distinct priority levels of arithmetic operators in c are-
Highest priority : * / %
Lowest priority : + -
Rules for evaluation of
expression
1. First parenthesized sub expression from left to right are evaluated.
2. If parentheses are nested, the evaluation begins with the innermost
sub expression
3. The precedence rule is applied in determining the order of
application of operators in evaluating sub expressions
4. The associatively rule is applied when 2 or more operators of the
same precedence level appear in a sub expression.
5. Arithmetic expressions are evaluated from left to right using the
rules of precedence
6. When parentheses are used, the expressions within parentheses
assume highest priority
Hierarchy of operators
Operator Description Associativity
( ), [ ] Function call, array
element reference
Left to Right
+, -, ++, -
-,!,~,*,&
Unary plus, minus,
increment,
decrement, logical
negation, 1’s
complement, pointer
reference, address
Right to Left
*, / , % Multiplication,
division, modulus
Left to Right
Expressions
Combination of Operators and
Operands
Example 2 * y + 5
Operands
Operators
Type Conversions
There are two kinds of type conversion.
Automatic or implicit type conversion
and
Explicit type conversion.
Type Conversion
Converting from one data type to another type is called type
conversion.
There are two kinds of type conversions.
Type Conversion
Implicit Explicit
Converting from one data type to another type is called type
conversion.
There are two kinds of type conversions.
Type Conversion
Implicit Explicit
Implicit: Same data type conversion
Smaller data type into bigger
(memory size)
Explicit: Different Data type
Type Casting
(Float--- int (or) int ---- float)
Type Conversion
Thank You
You Gave me
Your time

More Related Content

What's hot (20)

C operators
C operatorsC operators
C operators
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
2. operators in c
2. operators in c2. operators in c
2. operators in c
 
C# operators
C# operatorsC# operators
C# operators
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Operator of C language
Operator of C languageOperator of C language
Operator of C language
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operators
OperatorsOperators
Operators
 
Operators in c++
Operators in c++Operators in c++
Operators in c++
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 
Operators
OperatorsOperators
Operators
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 

Viewers also liked

The different rhinoplasty procedures
The different rhinoplasty proceduresThe different rhinoplasty procedures
The different rhinoplasty proceduresHealth First
 
exhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractorsexhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractorsexhibithire
 
Bespoke glasses | Cool Eyewear
Bespoke glasses | Cool EyewearBespoke glasses | Cool Eyewear
Bespoke glasses | Cool EyewearMono Qool
 
The many hidden causes of hip pain
The many hidden causes of hip painThe many hidden causes of hip pain
The many hidden causes of hip painHealth First
 
The 8 different sub disciplines of urology
The 8 different sub disciplines of urologyThe 8 different sub disciplines of urology
The 8 different sub disciplines of urologyHealth First
 
Tension fabric-printing-inspiration-guide
Tension fabric-printing-inspiration-guideTension fabric-printing-inspiration-guide
Tension fabric-printing-inspiration-guideexhibithire
 
VGIPM_Conference_CTA_2013_Abstracts[1]
VGIPM_Conference_CTA_2013_Abstracts[1]VGIPM_Conference_CTA_2013_Abstracts[1]
VGIPM_Conference_CTA_2013_Abstracts[1]Carlos Castilho
 
event planning,exhibition,designers,events management,companies,contractors
event planning,exhibition,designers,events management,companies,contractorsevent planning,exhibition,designers,events management,companies,contractors
event planning,exhibition,designers,events management,companies,contractorsexhibithire
 

Viewers also liked (11)

The different rhinoplasty procedures
The different rhinoplasty proceduresThe different rhinoplasty procedures
The different rhinoplasty procedures
 
exhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractorsexhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractors
 
Bespoke glasses | Cool Eyewear
Bespoke glasses | Cool EyewearBespoke glasses | Cool Eyewear
Bespoke glasses | Cool Eyewear
 
The many hidden causes of hip pain
The many hidden causes of hip painThe many hidden causes of hip pain
The many hidden causes of hip pain
 
The 8 different sub disciplines of urology
The 8 different sub disciplines of urologyThe 8 different sub disciplines of urology
The 8 different sub disciplines of urology
 
Tension fabric-printing-inspiration-guide
Tension fabric-printing-inspiration-guideTension fabric-printing-inspiration-guide
Tension fabric-printing-inspiration-guide
 
C function
C functionC function
C function
 
VGIPM_Conference_CTA_2013_Abstracts[1]
VGIPM_Conference_CTA_2013_Abstracts[1]VGIPM_Conference_CTA_2013_Abstracts[1]
VGIPM_Conference_CTA_2013_Abstracts[1]
 
SGI. PROFILE
SGI. PROFILESGI. PROFILE
SGI. PROFILE
 
event planning,exhibition,designers,events management,companies,contractors
event planning,exhibition,designers,events management,companies,contractorsevent planning,exhibition,designers,events management,companies,contractors
event planning,exhibition,designers,events management,companies,contractors
 
Data type in c
Data type in cData type in c
Data type in c
 

Similar to Coper in C

Similar to Coper in C (20)

c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
operator (1).pptx
operator (1).pptxoperator (1).pptx
operator (1).pptx
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ chapter 2
C++ chapter 2C++ chapter 2
C++ chapter 2
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
 
Theory3
Theory3Theory3
Theory3
 
Report on c
Report on cReport on c
Report on c
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 

More from thirumalaikumar3

More from thirumalaikumar3 (7)

Control flow in c
Control flow in cControl flow in c
Control flow in c
 
C basics
C   basicsC   basics
C basics
 
Structure c
Structure cStructure c
Structure c
 
String c
String cString c
String c
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
 
Data type2 c
Data type2 cData type2 c
Data type2 c
 

Recently uploaded

(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdfMJDuyan
 
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of Cybersecurity
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of CybersecurityDORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of Cybersecurity
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of CybersecurityPECB
 
647291105-Ppt-Arts-10-4th-Quarter-1.pdfi
647291105-Ppt-Arts-10-4th-Quarter-1.pdfi647291105-Ppt-Arts-10-4th-Quarter-1.pdfi
647291105-Ppt-Arts-10-4th-Quarter-1.pdfijoemmbrillantes
 
Sarah Lahm In Media Res Media Component
Sarah Lahm  In Media Res Media ComponentSarah Lahm  In Media Res Media Component
Sarah Lahm In Media Res Media ComponentInMediaRes1
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
How to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPHow to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPCeline George
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Farrington HS Streamlines Guest Entrance
Farrington HS Streamlines Guest EntranceFarrington HS Streamlines Guest Entrance
Farrington HS Streamlines Guest Entrancejulius27264
 
Paul Dobryden In Media Res Media Component
Paul Dobryden In Media Res Media ComponentPaul Dobryden In Media Res Media Component
Paul Dobryden In Media Res Media ComponentInMediaRes1
 
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdfMJDuyan
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsArubSultan
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...EduSkills OECD
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 
16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptxUmeshTimilsina1
 
Executive Directors Chat Initiating Equity for Impact.pdf
Executive Directors Chat  Initiating Equity for Impact.pdfExecutive Directors Chat  Initiating Equity for Impact.pdf
Executive Directors Chat Initiating Equity for Impact.pdfTechSoup
 
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdfMJDuyan
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptxmary850239
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
 
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of Cybersecurity
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of CybersecurityDORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of Cybersecurity
DORA, ISO/IEC 27005, and the Rise of AI: Securing the Future of Cybersecurity
 
647291105-Ppt-Arts-10-4th-Quarter-1.pdfi
647291105-Ppt-Arts-10-4th-Quarter-1.pdfi647291105-Ppt-Arts-10-4th-Quarter-1.pdfi
647291105-Ppt-Arts-10-4th-Quarter-1.pdfi
 
Sarah Lahm In Media Res Media Component
Sarah Lahm  In Media Res Media ComponentSarah Lahm  In Media Res Media Component
Sarah Lahm In Media Res Media Component
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
How to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPHow to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERP
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Farrington HS Streamlines Guest Entrance
Farrington HS Streamlines Guest EntranceFarrington HS Streamlines Guest Entrance
Farrington HS Streamlines Guest Entrance
 
Paul Dobryden In Media Res Media Component
Paul Dobryden In Media Res Media ComponentPaul Dobryden In Media Res Media Component
Paul Dobryden In Media Res Media Component
 
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristics
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 
16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx
 
Executive Directors Chat Initiating Equity for Impact.pdf
Executive Directors Chat  Initiating Equity for Impact.pdfExecutive Directors Chat  Initiating Equity for Impact.pdf
Executive Directors Chat Initiating Equity for Impact.pdf
 
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 1) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 

Coper in C

  • 1. OPERATORS & EXPRESSIONS An operator is a symbol (+,-,*,/)that tells the compiler to perform specific mathematical or logical manipulations. C language is rich in built-in operators and provides the following types of operators:
  • 2. Operators in C 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators
  • 3. Arithmetic operators Operator example Meaning + a + b Addition –unary - a – b Subtraction- unary * a * b Multiplication / a / b Division % a % b Modulo division- remainder
  • 4. Compound Assignment Operator ● Often we use “update” forms of operators – x=x+1, x=x*2, ... ● C offers a short form for this: – Generic Form variable op= expr equivalent to variable = variable op expr Update forms have value equal to the final value of expr ● i.e., x=3; y= (x+=3); /* x and y both get value 6 */ Operator Equivalent to: x *= y x = x * y y -= z + 1 y = y - (z + 1) a /= b a = a / b x += y / 8 x = x + (y / 8) y %= 3 y = y % 3
  • 5. Comma Operator has Lowest Precedence i.e it is having lowest priority so it is evaluated at last. Comma operator returns the value of the rightmost operand when multiple comma operators are used inside an expression. Comma Operator Can acts as – Operator : In the Expression Separator : Declaring Variable , In Function Call Parameter List Comma Operators
  • 6. Let a=5 and b=10 a++; //a becomes 6 a--; //a becomes 5 ++b; //a becomes 11 --b; //a becomes 9 Program for pre­increment &post­increment #include<stdio.h> Output : void main() Value of a : 10 { Value of b : 11 int a,b,x=10,y=10; a = x++; b = ++y; printf("Value of a : %d",a); printf("Value of b : %d",b); } PRE­INCREMENT & POST INCREMENT
  • 7. Relational Operator Meaning > Greater than >= Greater than or equal to <= Less than or equal to < Less than == Is equal to != Is not equal to Logical Operator Name of the Operator && And Operator | Or Operator ! Not Operator Operators
  • 8. Examples Truth Table a b Value of the expression a&& b a || b 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 Shorthand Assignment operators Simple assignment operator Shorthand operator a = a+1 a + =1 a = a-1 a - =1 a = a* (m+n) a * = m+n a = a / (m+n) a / = m+n a = a %b a %=b
  • 9. Conditional Operators [ ?: ] : Ternary Operator Statement in C expression 1 ? expression 2 : expression 3 where expression1 is Condition expression2 is Statement Followed if Condition is True expression2 is Statement Followed if Condition is False
  • 10. BITWISE OPERATORS Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right These operators allow manipulation of data at the bit level
  • 11. Review – Bitwise Operations in Integers • & – AND ● Result is 1 if both operand bits are 1 • | – OR ● Result is 1 if either operand bit is 1 • ^ – Exclusive OR ● Result is 1 if operand bits are different • ~ – Complement ● Each bit is reversed • << – Shift left ● Multiply by 2 • >> – Shift right ● Divide by 2 Corresponding bits of both operands are combined by the usual logic operations. Apply to all kinds of integer types:– Signed and unsigned char, short, int, long, long long
  • 12. Assume if A = 60; and B = 13; now in binary format they will be as follows: A = 0011 1100 B = 0000 1101 --------------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011 The Bitwise operators supported by C language are listed in the following table. Assume variable A holds 60 and variable B holds 13, then: Example for Bitwise Operations
  • 13. Special operators 1. Comma operator ( ,) 2. sizeof operator – sizeof( ) 3. Pointer operators – ( & and *) 4. Member selection operators – ( . and ->)
  • 14. ● BODMAS RULE- Brackets of Division Multiplication Addition Subtraction PRECEDENCE OF OPERATORS Brackets will have the highest precedence and have to be evaluated first, then comes of , then comes division, multiplication,addition and finally subtraction. The 2 distinct priority levels of arithmetic operators in c are- Highest priority : * / % Lowest priority : + -
  • 15. Rules for evaluation of expression 1. First parenthesized sub expression from left to right are evaluated. 2. If parentheses are nested, the evaluation begins with the innermost sub expression 3. The precedence rule is applied in determining the order of application of operators in evaluating sub expressions 4. The associatively rule is applied when 2 or more operators of the same precedence level appear in a sub expression. 5. Arithmetic expressions are evaluated from left to right using the rules of precedence 6. When parentheses are used, the expressions within parentheses assume highest priority
  • 16. Hierarchy of operators Operator Description Associativity ( ), [ ] Function call, array element reference Left to Right +, -, ++, - -,!,~,*,& Unary plus, minus, increment, decrement, logical negation, 1’s complement, pointer reference, address Right to Left *, / , % Multiplication, division, modulus Left to Right
  • 17. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators
  • 18. Type Conversions There are two kinds of type conversion. Automatic or implicit type conversion and Explicit type conversion.
  • 19. Type Conversion Converting from one data type to another type is called type conversion. There are two kinds of type conversions. Type Conversion Implicit Explicit Converting from one data type to another type is called type conversion. There are two kinds of type conversions. Type Conversion Implicit Explicit
  • 20. Implicit: Same data type conversion Smaller data type into bigger (memory size) Explicit: Different Data type Type Casting (Float--- int (or) int ---- float) Type Conversion
  • 21.
  • 22. Thank You You Gave me Your time