You are on page 1of 18

Operator & Expression

40102

(expression)
(operator) (operand)

(operator)
+ - *

% = > <

(operand)

(variable) , (constant) ,
(return function) (expression)
a+b , x++ ,
a != b , x = (a + b) / 2

a *
b - 3 )
operand #1 (constant)
operand #2
operator
(Expression
opera (*)
)
( nd
a * b
- operato
3 )
r



+ / * / %

+, -, * , / , , ,
% (modulo, mod)


0
1
2
3
4

%
%
%
%
%

3
3
3
3
3

=>
=>
=>
=>
=>

0
0
0
1
1

0
1
2
0
1

0 - 1

Implicit type conversion


operand
operator

a / b , a b

a b int
int
a b

Implicit type conversion


char , short , int , long ,


float , double

5 =>
5.0 =>

Implicit type conversion:


char ch ;
int i ;
float f ; double d ;

result = ( ch
/
i )
f
* int
d ) - double
( f
+
int

double

double

double

double

+
(
i ) float
;

float
double


C = ( 5 / 9 ) * ( F 32 )

float degC , degF ;

degC = ( 5.0 / 9.0 ) * ( degF 32 ) ;

float

float float
float

float int
float
float

float

(operator)

a + b * c
5.0
d // 9.0
e *
F 32

1
2
3

( a + ( b * c )
)( ( 5.0
( d / 9.0
e ) )
*
F
)
32
Operators
()
* / %
+ -

= += -= *= /= %=

=
(
) a = 3 + 5 / 4 ;
+= , -= , *= , /= , %=

Count += 2 ;

Count = Count + 2 ;
Score = 2.53 ;
Score = Score 2.53 ;

++ -
a += 1
--
a -= 1
++ , --



a++ , a--)
(
a
a += 1 a -= 1

++a , --a)

(
a += 1 a -= 1
a
++

a++ a
a 1

i =
i = 3
3 ;
;
b =
b =
i ;
i++;
ib= i
= 3 , i = 4
+ 1 ;

a
++a
1 a

i =
i = 3

3 ;
;
i = i
b =
+ 1 ;
++i;
bb = i;
= 4 , i = 4

a-- a

a 1

i =
i = 3

3 ;
;
b = i;
b =
i = i i--;
1b ;
= 3 , i = 2

--a a
1 a

i =
i = 3

3 ;
;
i = i b =
1 ;
--i;
bb = i;
= 2 , i = 2

> , < , >= , <= , == , !=


50

pass

fail 50

>
<
>=
<=
==
!=

ex4.cpp
#include <stdio.h>
void main()
{
int num1,num2;
printf("Enter 2 integer, and I will tell you\n");
scanf("%d%d",&num1,&num2);
if (num1 < num2)
{
printf("%d is less than %d\n",num1,num2);
}
} // end program

if (num1 > num2)


{
printf("%d is greater than %d\n",num1,num2);
}


if
<= , >= , == , !=

You might also like