0% found this document useful (0 votes)
35 views

EID2623 Operators

The document discusses different types of operators in C programming including arithmetic, relational, logical, and bitwise operators. It provides examples of using each type of operator and explains their functionality. Truth tables are provided for bitwise AND, OR, and XOR operators. Examples are given showing how to use bitwise operators in code using the &, |, and ^ operators.

Uploaded by

AngCW
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

EID2623 Operators

The document discusses different types of operators in C programming including arithmetic, relational, logical, and bitwise operators. It provides examples of using each type of operator and explains their functionality. Truth tables are provided for bitwise AND, OR, and XOR operators. Examples are given showing how to use bitwise operators in code using the &, |, and ^ operators.

Uploaded by

AngCW
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Control Operations

Control Operations
Operators
Arithmetic Operators (+ ,- ,* ,/, %)
Bitwise Operators (&, |, ^, !)
Unary Operators (++, --)
Relational Operators
To compare the relationship between operands and bring out a
decision and program accordingly.
greater >
greater or equal >=
lesser <
lesser or equal <=
equal ==
not equal !=
Logical Operators
To compare or evaluate logical and relational expressions.
OR gate ( || )
AND gate (&&)

Arithmetic Operators
#include<stdio.h>
int main()
{
int a = 10, b = 2 , c;
c = a + b;
printf("The sum of a and b is %d\n", c);
c = a - b;
printf("The a - b is %d\n", c);
c = a * b;
printf("The a X b is %d\n", c);

The sum of a and b is 12

c = a / b;
printf("The a / b is %d\n", c); The a b is 8
return 0;
}

The a x b is 20
The a / b is 5

Bitwise Operators
Truth Table
AND Gate (&)

OR Gate (|)

AND

OR

EX-ORGate (^)
XOR

Bitwise Operators
#include<stdio.h>
int main()
{
int a = 0xff, b = 0x07, c , d;

c = a & b;
printf("Result bitwise AND is %x\n", c);
c = a | b; 0xff
1111 1111
printf("Result bitwise OR is %x\n", c);
0000 0111
c = a ^ b; 0x07
printf("Result
bitwise
EX-OR
0xff
1111
1111
AND gate
0000
0111is %x\n", c);
c = ! (a & b);
0xff
1111
1111
0x07 bitwise
0000
0111
printf("Result
NOT
is %x\n", c);
d = b<<3; 0x07
00000111
OR
1111
0xffgate
11111111
1111
printf("Result shift to left 3 steps is %x\n", d);
Ex-OR
0x07 gate 1111
00001000
0111
return 0; 0x07
00000111
AND gate
0000 0111
00111000

Input - Friends
Process - You
Output - Friends

& gate

| gate

Not gate

ExOR

Not | gate

Not & gate

Condition operator

More on operations
Equals symbol = is used for assignment
Double equals symbol == is used for equality

Example:
a = b +1;

assign value to a

a = = b +1;

test whether a is equal to b+1

a != b + 1;

test whether a is not equal to b+1

More on operations
Assignments of the form:
y = y+1;
increment the current value of y
It is equal to y++ ;
i.e y++ is post increment, ++y is pre increment
sum = x + y++ is not same as sum = x + ++y

Incremental operations:
if y = 4 and x = 7 determine
sum = x + (y++);

sum is 11 because 11 = 7 + 4

sum = x + (++y);

sum is 12 because 12 = 7 + 5

sum = (x++) + (--y);

sum is 10 because 10 = 7 + 3

sum = (--x) + 2*(++y);

sum is 16 because 16 = 6 + 2*5

sum = (++x) - 4*(--y);

sum is -4 because -4 = 8 - 4*3

Trace the output:


#include<stdio.h>
int main()
{
int a, b, c=0;
a=++c;
b=c++;
printf ("%d %d %d\n", a, b, ++c);
return(0);
}

The End of
Operation

You might also like