Module 2 - Operators in C, Type Conversion and Typecasting
Module 2 - Operators in C, Type Conversion and Typecasting
int ma'n ()
Iong in+ numl = 1234661, num2, ett O
50> 100
65<66
=| 20 10<
O 20 > 10
=I 20 ! 10
10<20
l
print(d<1d"
Y); X<: Y, x,
Y); >>= >= d
4, <, d) = dprint4("n
y); >+d,y, -l= -d>print4("n
); x{= =d,x,y, -dd!= ("n printf
); y, , .d d : =d printt(
Y); y, x,d", .d= d< (n prntf
;20 =10,
E xint
() main int
<stdio.h> inlude #
ational of use hshow grarn
pr'to writea
s
Conguage aupparts 2 Mincdh of equalty operadrs
tommpare Hheir operands for s4rict equality
UY
to
(n) 4a(6>c)
6for ezample exmeuions
ony it boh
- The egrsjon isbistrue
qresatr than both ac.
nre Hrue ie if
ande. oboth Hhan
r à bor cthorn qreadir han
qral b
iseither iftrue isienpres rohole The
-the
t (0cb) lett
is to
theepresion The -
Cb>) (osb)
exampe. 11 For
4
Tabk Trh
volu. drue returns
a o4hrise
+
s heboth ifvae olse eturns
a doq'
oRcal -
o.
dapal
doual NoT
The NOT operasthr tuies a Aingu oxres ron
expesion,
-Thad is bal NOT rooluus a oit t expresion
oT moobues
ewaluai do caa non zero vauue 4 procluu a 1 if
rpesion prodey a 0.
Trath abl
A A.
or oample.
inta = 10, b;
b loj
- Nou the value ot b=0, This is becauee vaue ot
to b,
henu the yut.
Vyary Oprntos. .
Unary operatar at on sna oerands. C targuage
hree unary operadns.
>Uhary Minus.
fos
lhany mins (-) operadof s striningy derent2 qperndd
the binary arithmetie oprador Hfid oparala on 2 opeand
4suhdracds f kecorol operanol from hu fet
- whn an operand s pre eeded by a minus Siyn,
he unasy operator negab1 its vabe.
For Eycample : int o, b 10
a-(b):
where as
>Write t program to ilhusdall he wwe
intemunt d- ooeremant operatrs. opn)
include <stdio. h>
t man )
int num 3)
7Usina unary prefr inremurd operadr
printtnThe vale
vabu ot num d" num);
tnum
prindt ("n The new valuu of num = l', num);
using unary preaix deerenand eperatr
prind(n\n The value at um dd num);
printft"n The valu of -num);
printnThe new vale ot numtd" num);
return
3
oud pudt
The valut ot num
The ttnum 4
num = 4
The new vau ot
The num
num
The vale ot
num e3.
The new valu
postefra inerement dcrenont epratrt, unary ap
int main ()
int num=3
I Os ingy unary postf ineremunt qpertr
prontf"n The valae of oume Y. d num):
printt ( The vale of num+t = d) num++);
prindf("The new vaeof nun = 1d,num);
l using nary poctfx ocYemnt eperasar
-d num);
um
printf" The vale of numz d, num- -);
rintt("o The ned value ot numz d" pum);
The valu ot
The vas ot num++ 3
The new vaue ot num : 4
value of num
valus of num- 4
The
num 3.
The new
(onditiorad Operatr
jt
-Thh tonditimal operator orrthe ternary (?:)j
LHe an it-ee sdo,tement that tan be wed i thin
epension.
example Largg =(a>b) ?o:b
- Here tonbitional operabr i med to fndl the large r
fiven num bers.
-First pl, hat is (osb) * evaluatd.
-If a is gyreatr than b, ten larqg z o,
=b.
- Hlenu, aree is equal do either a orb but t
both
Seiod 34
23
Thd
number s : 34
Lagt mumber
BHwise bperator
-Bidaise opndbrs are oe opradrs udt prform
operadhons ot bit bve.Thy inc uca bitoise AND,
bidoise oR, bitwise x0R, 4-shift operators,
When we ugehe bitwise AND perast r ke bit in the
` ANDed widh he orrponclin bit in the
Beconed oprarel. The truth dabk is gane
logical AD operaston.
VOi mei n )
4
int a=21, b:3 ;
+b);
a lb):;
printt ("
printf ("
(
printf b= d,vb);
printf ("n s<i);
print4( n a<<|=d
b>>|rd) b>>);
rint4(N
2); num hum
,
=num2 nuond
and =d num 1
thetvalustion
of the After (n1 printf
2); num numl, d num2
num: (nitial
ofvelue printt
nd dd
numl3,
numn2 int
man() int
stio.h induce
< opeetns #
the
ot use monstruli de torvercr
kr<<Exp var=Var<K=Exp
Nar-brip ExVar^:
p
ar=hr4En cExp Varg
Var-tup Narz =Exp Var-
tExp Var Varc &xp Vart
are *xp Var
Vor_or\fp énp var
Varls. Var:
Eaivdo syoax. Operatr
ruponsibu
fo
opl6
indial vabe anel hum2 5
AfHer fhe valuatn ot the xpesiin num1l6
and num2=5.
lommo operaor.
ope
rancle. l+
- The tovma operastor in Ctokes 2
Worhs
by evalaing te frst + dis cardng
rurns
Ylue, evauat
ken seconel
cherer : A
The cha'iati in lower ese is: q.
Write a roran to swap two nmbers using 4
Jen porary voiriable.
F inclucde <stcdio.h
int main ()
lint nunl, num2, tenpi
clrserl); tatec the trst nun be r: ");
printf (
scan t ( num 1);
priotfC"o koder RSecond humber: );
Hem
tmum 2 temp)
print f(n The trstnumber is d num )
printf( n The adnd number it Td num2);
Saanel
The tirst number si 5
Beenl
two numbers othout
>Ne a proyram do Bwa
wsing a temporary variable.
incude cstdioh> ati tf tist o : 3
- 12
voiart of i2
12 is 12-00000.
The fosing goid