c ppt
DESCRIPTION
TRANSCRIPT
![Page 1: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/1.jpg)
04/10/23 By Jag1
![Page 2: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/2.jpg)
04/10/23 By Jag2
Topics
Concept of Operators
Classification of operators
![Page 3: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/3.jpg)
04/10/23 By Jag3
Classification
Arithmetic operators Conditional operators Bitwise operators Relational operators Logical operators Assignment operators Increment and decrement operators Special operators
![Page 4: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/4.jpg)
04/10/23 By Jag4
Arithmetic Operators
Integer Arithmetic Real Arithmetic Mixed –mode Arithmetic
![Page 5: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/5.jpg)
04/10/23 By Jag5
Integer Arithmetic
Operands in a single arithmetic expression Operation is integer arithmetic E.g. If a =14 and b=4 a-b=10 a+b=18 a/b=3 a%b=2
![Page 6: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/6.jpg)
04/10/23 By Jag6
Use of integer arithmetic
main(){
int months, days;printf(“Enter days\n”);scanf(“%d, &days”);
months=days/30;days=days%30;
printf(“Months=%d Days=%d”, months, days);}
![Page 7: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/7.jpg)
04/10/23 By Jag7
Real Arithmetic
Real operator is known as real arithmetic. Decimal and exponential notation
If x,y are floats
x=6.0/7.0=0.857143
y=-2.0/3.0=-0.666667
![Page 8: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/8.jpg)
04/10/23 By Jag8
Mixed –mode Arithmetic
One of the operands is real and the other is integer
For example
19/10.0=1.9
![Page 9: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/9.jpg)
04/10/23 By Jag9
Conditional operators
The conditional operator consists of 2 symbols the question mark (?) and the colon (:)
Syntax:
exp1 ? exp2: exp3
![Page 10: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/10.jpg)
04/10/23 By Jag10
Example
a=16b=25; x=(a>b) ? a : b;
if (a>b) x=a; else x=b;
![Page 11: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/11.jpg)
04/10/23 By Jag11
Bitwise operators
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise Exclusive
<< Shift left
>> Shift right
![Page 12: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/12.jpg)
04/10/23 By Jag12
Result of logical Bitwise Operation
op1 op2 op1&op2 op1|op2 op1^op2
1 1 1 1 0
1 0 0 1 1
0 1 0 1 1
0 0 0 0 0
![Page 13: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/13.jpg)
04/10/23 By Jag13
Example
Bitwise AND
x - - -> 0000 0000 0000 1101y - - -> 0000 0000 0001 1001
x&y- - -> 0000 0000 0000 1001
Bitwise OR
x - - - > 0000 0000 0000 1101y - - -> 0000 0000 0000 1001x|y - - -> 0000 0000 0001 1101
![Page 14: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/14.jpg)
04/10/23 By Jag14
Bitwise Exclusive OR
x - - -> 0000 0000 0000 1101
y - - -> 0000 0000 0001 1001
x^y - - -> 0000 0000 0001 0100
![Page 15: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/15.jpg)
04/10/23 By Jag15
Bitwise shift operators
Left shift
op<<n
Eg. 0100 1001 1100 1011
x<<3
Right shift
op>>n
![Page 16: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/16.jpg)
04/10/23 By Jag16
Bitwise Complement Operators
~ one’s complement operator is a unary operator.
![Page 17: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/17.jpg)
04/10/23 By Jag17
Relational Operators
Operator Meaning
< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to
== is equal to
!= is not equal to
![Page 18: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/18.jpg)
04/10/23 By Jag18
Logical operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
![Page 19: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/19.jpg)
04/10/23 By Jag19
Examples
Logical AND (&&) a > b && x = = 10
Logical OR (||) a < m || a < n
Logical NOT (!)
! (x >= y)
![Page 20: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/20.jpg)
04/10/23 By Jag20
Assignment Operators
In addition, C has a set of shorthand assignment operators of the form. var oper = exp;
Example x = a + b
![Page 21: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/21.jpg)
04/10/23 By Jag21
Increment and Decrement
syntax: 1. ++variable name
2. variable name++ 3. – –variable name 4. variable name– –
x= 5; y = ++x; (prefix)
In this case the value of y and x would be 6
x= 5; y = x++; (post fix)
Then the value of y will be 5 and that of x will be 6.
![Page 22: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/22.jpg)
04/10/23 By Jag22
Special operators
Comma operator Size of operator Pointer operators (& and *) Member selection operators (. and ->).
![Page 23: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/23.jpg)
04/10/23 By Jag23
Comma operator
Link related expressions together Expressions are evaluated left to right
for e.g.
value = (x = 10, y = 5, x + y);
for (n=1, m=10, n <=m; n++, m++)
![Page 24: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/24.jpg)
04/10/23 By Jag24
The sizeof Operator
Gives of bytes occupied in the memory. To determine the lengths of arrays and structures
when their sizes are not known to the programmer
for e.g.
x = sizeof (sum); y = sizeof (long int); z= sizeof (235L);
![Page 25: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/25.jpg)
04/10/23 By Jag25
Precedence and Associativity
Precedence rules decides the order in which different operator are applied.
Associativity rule decides the order in which multiple occurrences of the same level operator are applied.
![Page 26: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/26.jpg)
04/10/23 By Jag26
Summary of C operator
Description Operator Rank Associativity
Function callArray element reference
( )[]
1 Left to right
Unary plus Unary minus Increment Decrement Logical negationOnes complement AddressSize of an object
+-++--!~&Sizeof
2 Right to left
MultiplicationDivisionModulus
*/%
3 Left to right
AdditionSubtraction
+-
4 Left to right
Left shiftRight shift
<<>>
5 Left to right
Less thanLess than equal toGreater than Greater than equal to
<<=>>=
6 Left to right
EqualityInequality
= =|=
7 Left to right
![Page 27: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/27.jpg)
04/10/23 By Jag27
Continue….
Bitwise AND & 8 Left to right
Bitwise XOR ^ 9 Left to right
Bitwise OR | 10 Left to right
Logical AND && 11 Left to right
Logical OR || 12 Left to right
Conditional operator ?: 13 Right to left
Assignment operator =*=/=%=+=-=&=^=|=<< = >>=
14 Right to left
Commas operator , 15 Left to right
![Page 28: C ppt](https://reader036.vdocuments.mx/reader036/viewer/2022070304/54be6ad64a7959d0468b456d/html5/thumbnails/28.jpg)
04/10/23 By Jag28