You are on page 1of 19

# C Operators

1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increments and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators

## CO2. To gain knowledge about the control structures in C

Arithmetic operators
Operator Meaning

## – Subtraction or Unary Minus

* Multiplication

/ Division

% Modulus Operator
CO2. To gain knowledge about the
control structures in C
Integer Arithmetic
Let x = 27 and y = 5
z=x+y  32
z=x–y  22
z=x*y  115
z=x%y  2
z=x/y  5

## CO2. To gain knowledge about the

control structures in C
Floating point arithmetic
Let x = 14.0 and y = 4.0 then
z=x+y  18.0
z=x–y  10.0
z=x*y  56.0
z=x/y  3.50

## CO2. To gain knowledge about the

control structures in C
Relational Operators
Operator Meaning

## >= is greater than or equal to

== is equal to

!= isCO2.
not equal to
control structures in C
Relational Expressions
6.5 <= 25 TRUE
-65 > 0 FALSE
10 < 7 + 5 TRUE

## CO2. To gain knowledge about the

control structures in C
Logical Operators
Operator Meaning

## && Logical AND

|| Logical OR

! Logical NOT
CO2. To gain knowledge about the
control structures in C
a > b && x = = 10
a < m || a < n
! (x >= y)

a=5
b=4
x=10, y = 9
m=6
n=3
CO2. To gain knowledge about the
control structures in C
Assignment Operators
Statement with simple Statement with
assignment operator shorthand operator

a=a+1 a += 1

a=a–1 a -= 1

a = a * (n+1) a *= (n+1)

a = a / (n+1) a /= (n+1)

a = a %control
b structures in C a %= b
CO2. To gain knowledge about the
What is the output?
#define N 100
#define A 2
main() Output
{
int a; 2
a = A; 4
while (a < N) 16
{ 25
printf(“%d \n”,a);
a *= a;
}
} CO2. To gain knowledge about the
control structures in C
Increment and Decrement Operators

1. ++ v m = 5;
2. v++ y = ++m; (prefix)
After Execution:
3. – –v
y=6, m=6
4. V--

m = 5;
y = m++; (post fix)
After Execution:
y=5, m=6
CO2. To gain knowledge about the control structures
in C
Conditional or Ternary Operator

a = 10;
b = 15;
x = (a > b) ? a : b

## CO2. To gain knowledge about the control structures

in C
Bitwise Operators
Operator Meaning

## & Bitwise AND

| Bitwise OR

^ Bitwise Exclusive

>> Shift right

## CO2. To gain knowledge about the control structures in C

Special Operators
comma operator
size of operator
pointer operators (& and *)
member selection operators (. and ->).

## CO2. To gain knowledge about the

control structures in C
The Comma Operator
value = (x = 10, y = 5, x + y);

In for loops:
for (n=1, m=10, n <=m; n++,m++)

In while loops
While (c=getchar(), c != ‘1’)

Exchanging values

t = x, x = y, y = t;
CO2. To gain knowledge about the
control structures in C
The size of Operator
Operat
m = sizeof (sum);
n = sizeof (long int);
k = sizeof (235L);

## CO2. To gain knowledge about the

control structures in C
What is the output?
main()
{
int a, b, c, d;
a = 15; b = 10; c = ++a-b;
printf (“a = %d, b = %d, c = %d\n”, a,b,c);
d=b++ + a;
printf (“a = %d, b = %d, d = %d\n, a,b,d);
printf (“a / b = %d\n, a / b);
printf (“a %% b = %d\n, a % b);
printf (“a *= b = %d\n, a *= b);
printf (“%d\n, (c > d) ? 1 : 0 );
printf (“%d\n, (c < d) ? 1 : 0 );
}

## CO2. To gain knowledge about the

control structures in C
A=16,b=10,c=

## CO2. To gain knowledge about the

control structures in C
CO2. To gain knowledge about the
control structures in C