emeronTI2 ³
kenSam Expression & Statement I. RbePTTinñn½y I.1. niymn½y
Tinnñ y½ (Data) KÅCabNþaBt’manEdlmanBitdUcCa GtßbT tMélelx sMelg nig rUbPaB sMEdgeRkamTMrg;mYyEdlkuMBüÚT½rGaceFVIkarR)aRs½yTak;Tg b¤Gnuvtþn_ kargarNamYyCamYyva)an.
I.2. RbePTTinñ½y (Data Type)
kñúgPasa C manRbePTTinñn½ymYycMnYndUc)anbgðajxageRkamenH ³
RbePTTinñn½yRtUv)aneKeGayniymn½yedayBIrcMnucxageRkamKW ³ + CaRbePT nigEdnkMNt;éntMél EdleRkayeBlGefrmYy)anRbkas CamYyRbePTTinñn½yenaHrYc vaGacTTYlyktMélenaH)an. + kñúgRbePTTinñn½ynImYy²GacmankMNt;RbmaNviFImYycMnYnCak;lak;. I.3. RbePTcMnYnKt; ( Integer )
eyIgdwgehIyfa kñgú KNitviTüa cMnnY Kt;FmμCatimantMélcab;BI –N rhUtdl; N nigFatuTaMgGs;rYmcUlKñabegáIt)anCasMnuMcMnYnKt;. enAkñúgkuMBüÚT½rvaBuMmanlT§PaB sMEdgtMélelx )antaMgBI -∞ rhUtdl; +∞ enaHeT KWvaGacsMEdg)anEtenAcenøaH kMNt;NamYyén (-∞, +∞) b:ueNÑaH. dUecñHcMnYnKt; (Integer) enAkñúgkMuBüÚT½rKWman karEbgEckCaRbePTcMnYnKt; epSg²BIKñaeTot GaRs½yeTAtamEdntMélrbs;vadUc xageRkam ³
RbePTTinñn½y
EdntMél -128 dl; 127 -32768 dl;
BaküKnøwH
cMnYn Byte
char
1
int
2
Short integer
short
2
-32768 dl; 32767
Long integer
long
4
-2147483648 dl; 2147483647
unsigned char
1
0 dl; 255
unsigned int
2
0 dl; 65535
Unsigned short intger
unsigned short
2
0 dl; 65535
Unsigned long intger
unsigned long
4
0 dl; 4294967295
Character Integer
Unsigned character Unsigned intger
26
32767
cMNaM ³ RbePTTinñn½y char PaBBitCaRbePTGkSr k¾b:uEnþkñúgPasa C )anGnuBaØateGayeRbIRbePT char enHCacMnYnKt;mYyEdlmantMélGacsMEdg)an dUckñúgtaragxagelI. enHKWCaPaBrs;rvIkrbs; C EdlenAeBleFIVRbmaNviFInBVnþ enaHRbePTTinñn½y char RtUv)ancat;TukCacMnYnKt; Etdl;eBleFVIRbmaNviFICamYy tYGkSr enaHvacat;Tuk char CaRbePTtYGkSrvij. I.3.1. sMEdgcMnYnKt;edayelxeKal 16 nigeKal 8 enAkñúgkarsreskmμviFIedayPasa C eRkAGMBIkarsresrelxeRkamTMrg; Decimal (elxeKal 10) va)anpþl;lT§PaBeGayeyIgGacsresrelxeRkamTMrg; eKal 16 (hexa) EfmeTot. RbB½n§elxeKal 16 rYmman 16 tYelxKW ³ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F EdlkñúgenaH A, B, C, D, E, F tMNageGay 10, 11, 12, 13, 14, 15. kñúgPasa C edIm,IsresrelxeRkamTMrg; Hexa enaHRtUvsresrtamlMnaM xageRkam ³ Ox41mann½yfa 41 hexa EdlesIμnwg 65 decimal OxFmann½yfa F hexa EdlesIμnwg 15 decimal eRkABIkarsresrelxeRkamTMrg;CaRbB½n§ Hexa enaHkñúgPasa C enA GnuBaØateGayeyIgGaceRbIR)as;elxeRkamTMrg; Octal )anEfmeTotpg. RbB½ne§ lx Octal (RbB½n§elxeKal 8) rYmman 8 tYelxsMrab;eRbIKW 0, 1, 2, 3, 4, 5, 6, 7. edIm,IsMEdgelxNamYyeRkamTMrg; Octal enaHkñúgPasa C RtUvsresrcab;epþIm eLIgedayelxsUnü 0 (elxsUnü ). ]TahrN_ ³ 013 mann½yfa 13 Octal EdlesIμnwg 11 decimal 07 mann½yfa 7 Octal EdlesIμnwg 7 decimal I.3.2. Pa¢b;tMélcab;epþImeGayGefrRbePTcMnYnKt; ]bmafaeyIgP¢ab;tMél 5 eGayGefr x enaHeyIgGacsresr)anBIrrebob dUcxageRkam ³ int x; x = 5;
b¤sresr ³ int x = 5;
27
I.3.3. cMnYnefrRbePTcMnYnKt;
eBlxøHeyIgRtUvkarsresrcMnYnefredIm,IP¢ab;eGayGefr b¤brimaNGVImYy. edIm,ITTYl)annUv kMritsuRkitx<s; Kb,IeyIgRtUvsresrbBa¢ak;bEnßmnUvtYGkSrbBa¢ak; mYyenAEpñk xageRkay bMputrbs; bNþatYelxéntMélenaH. ]TahrN_ ³ 1000U )ann½yfaCacMnYnefrcMnYnKt; unsigned int EdlmantMél 1000 1000L )ann½yfaCacMnYnefrcMnYnKt;RbePT long EdlmantMél 1000 1000UL CacMnYnefrcMnYnKt;RbePT unsigned long EdlmantMél 1000 0100L CacMnYnefrcMnYnKt;RbePT long sresreRkamTMrg;elxRbB½n§eKal 8 0x1000U CacMnYnefrcMnYnKt;RbePT unsigned int EdlsresreRkamTMrg; RbB½n§elxeKal 16. I.4. cMnYnBit (Real )
dUcKñaCamYynwgRbePTTinñn½ycMnYnKt;Edr kñúgkMuBüÚT½rvaBMumanlT§PaBsMEdg tMélelxrbs; sMncuM nM nY Bit)anTaMgGs;enaHeT KW)anEtEpñkNamYyénsMnMuEtbue: NÑaH. kñúgPasa C RbePTcMnYnBitRtUv)anEckecjCabIRbePTepSg²eTotKW ³ RbePT float, double nig long dougle. enAeBlEdlGñksresrtMélelxsMEdgeRkamTMrg;RbB½n§ elxeKal 16 b¤eKal 8 enaHkñúgPasa C BMuGnuBaØateGayGñkeRbIsBaØaek,ós (.) )aneLIy. karsreselxdUcxageRkamenHmankMhus ³ 0x5.5 xus 05.5 eBlenHkuBM üÚTr½ BM)u anyl;faelxenHCaelxeKal 8 eT vaEbCayl; faenHCaelxeKal 10 EdlmantMélesμI 5.5. cMNaM ³ kñúgesÞrI RKb;PasasresrkmμvFi TI aMgGs; enaHEtgRtUv)aneKeRbIsBaØa (.) BMuEmnsBaØa (,) eT. 28
eBlsresrek,ósTsPaK
I.4.1. rebobsresrtMéléncMnYnBitkñúgPasa C
RtUv 3.0 RtUv -12.345 RtUv +0.00050 RtUv 3.1416
3. 0.5 .50
RtUv RtUv RtUv
5 5E-2 5,00
xus RtUv xus
CamYyKñaenH eyIgk¾GacsresrcMnYnTsPaKtamTMrg;dUcxageRkam ³ ]TahrN_ 2
3
512.34567 = 5.1234567.10 = 0.51234567.10 kñúgPasa C eyIgGacsresr ³
5.1234567E+02 (RtUvsresrCab;KñaTaMgGs;) mann½yfa 5.1234567*10
+2
dUcKñaenHEdr tMél -0.001234 eyIgGacsresr)anfa ³ -12.34E-4
I.4.2. RbePTcMnYnKt;
RbePTTinñn½y
BaküKnøwH
cMnYn
Byte
EdntMél 3.4E-38 dl;
Single-precision floating point
float
4
Doule-precision floating point
double
8
1.7E-308 dl; 1.7E+308
Long doubleprecision floating point
long double
10
3.4E-4932 dl; 1.1E+4932
29
3.4E+38
I.4.3. cMnYnefrRbePTcMnYnKt;
edIm,IsresrtMélcMnYnefrRbePTcMnYnBiteGaymanPaBsuRkitx<s; RtUvP¢ab;BIxageRkaytMélcMnYnBitenaHnUvtYGkSrbBa¢ak; F (float) b¤ L (long). ]TahrN_ ³ 0.12345E-33L CacMnYnefrRbePT long double 5.50123E+10F CacMnYnefrRbePT float .12345FCacMnYnefrRbePT float
enaHeyIg
I.4.4. P¢ab;tMélcab;epþImeGayGefrRbePTcMnYnKt;
eyIgGacP¢ab;tMélcab;epþmI eGayGefrRbePTcMnYnBit tamlMnaMdUcxageRkam ³ ]TahrN_ float x; x = .50;
b¤k¾Gacsresr ³ float x = .50;
I.5. Tinñn½yRbePT Char (Character Type)
kMuBüÚTr½ vaBMuRtwmEteFVkI arCamYyTinnñ ½yCatMélelxb:ueNÑaHeT EfmTaMgvaGaceFVI karCamYybNþatYGkSr (Letters) tYelx (Numerals) nigGaclayCamYybNþa sBaØaepSg (Sign) eTotpg EdlFatunImYy²rbs;sMnMuTaMgenHGacRtUv)aneKehAfa Ca Character. bNþa Character EdleyIgEtgEtCYbRbTH nigeRbIR)as;sBVéf¶man dUcCa a, b, c, …, z, A, B, C, …, Z, 0, 1, 2, …, 9, !, ?, \.l. kñúgPasa C edIm,IsresrcMnYnefrén Character eyIgRtUvsresr Character enaHenAkñúgcenøaHsBaØa ‘ ’ (single quote) ]TahrN_dUcCa ‘a’, ‘0’, ‘?’, ‘2’, ‘z’ CaedIm. Character TaMgGs;suT§EtRtUv)aneKkMNt;kUdtMNageGayva edIm,IgayRsYl kñúgkarrkSaTuk nigGnuvtþn_RbmaNviFIelIva. kñúgenaHEdr ASCII (American Standard Code 30
for Information Interchange) )ankMNt;kUdsMrab; 256 character nigeRbImYy Byte memory
edIm,IrkSaTukTinñn½y 1 character.
tarag ASCII xageRkamenH)anbgðaj 128 character dMbUg cMENk 128 eRkayeTot nwgRtUv)anbgðajenAkñúgesckþIbEnßménesovePAenH. 32 tYdMbUg (Edl mankUdcab;BI 0 dl; 31) CabNþa character bBa¢a Cak;EsþgdUcCakUd 7 Ca ASCII rbs; BELL )ann½yfaeBlEdlkMuBüÚT½rTTYl)antMélenH vanwgbeBa©jsMelgCYg (Bell). cMENkÉkUd 13 (CR-Carriage Return) nig 10 (LF-Line Feed) vijKWCa character bBa¢aeGay screen Gnuvtþn_kacuHbnÞat; nigRtLb;mkedImbnÞat;vij. cab;BI ASCII 32 rhUtdl; 127 CabNþa character EdlGacbgðajelIeGRkg; nig e)aHBum<ecjeRkA)an. tarag ASCII 128 tYdMbUg ³
31
kñúgPasa C eyIgGacsresrbNþa character bBa¢a)anedayeRbI EdleK)ankMNt;CaeRscdUctaragxageRkam ³ Constance character
ASCII
‘\a’
7
‘\b’
8
‘\t’
9
‘\n’
10
‘\r’
13
Constance character
muxgar
beBa©jsMelgCYg (BELL) lb;mkeqVgmYytYGkSr (Back Space) Character Tab ; cuHbnÞat;fμI (Line Feed) RtLb;eTAedImbnÞat; (Carriage Return)
eRkABIbNþa Character xagelIenH edIm,IsresrsBaØa b¤ Character Biess mYycMnYndUckñúgtaragxageRkam enaHRtUvdak; Character ‘\’ BIxagmuxsindUcCa ³ rebobsresr
Character
‘\‘’ ‘\“’ ‘\\’
‘ “ \
‘\0’
\0 b¤ NULL
cUrRby½tñcMeBaH Character ‘\0’ nig ‘0’ : + Character ‘\0’ KWCa Character EdlRtUv)aneKehAmü:ageTotfa NULL nigman ASCII = 0. + Character ‘0’ KWCatYelxsUnüEdlman ASCII = 48 decimal. ª karP¢ab;tMélcab;epþImeGayGefrRbePT char : eyIgGackMNt; b¤P¢ab;tMélcab;epþmI eGayGefrRbePT char )andUc]TahrN_ xageRkam ³ 32
]TahrN_ char x = ‘5’;
b¤k¾ char x ; x = ‘5’ ;
kmμviFIxageRkamenHCa]TahrN_bgðajGMBIkareRbIR)as;bNþa Character bBa¢a. cUrGñkvaykUdkmμvFi eI nHkñúgmCÄdæanRmbUlpþMú TURBO C rYcehIydMeNIrkarva CamYynwgkarBinitüemIlRKb;dMNak;kalénkarbþÚr b¤lub Character bBa¢aNamYy. kmμviFI Prog2_1.C xageRkamenHmankareRbI Character bBa¢amYycMnYndUcCa ‘\n’, ‘\t’, ‘\a’, ‘\’’, ‘\”’ .l. /*----------------------- Prog2_1.C -----------------------*/ #include <stdio.h> #include <conio.h> void main( ) { clrscr( ); printf("Hello every body ! \nThis is a program"); printf(" Showing about the Escape sequence."); printf("\nThis program just output text onto screen\n\n\a\a"); printf("\t1.\tGood morning !\n"); printf("\"Build Bright University\" \'BBU\'"); getch( ); }
lT§plelIeGRkg;KW ³ Hello every body ! This is a program Showing about the Escape sequence. This program just output text onto screen 1. Good morning ! "Build Bright University" 'BBU'
33
I.6. Tinñn½yRbePT String
kñúgPasa C String KWCaes‘rIén Character EdlRtUv)aneKsresrdak;kñúg cenøaHsBaØa “ ” (double quotes) ]TahrN_dUcCaXøa “Cambodia”. FatunImYy² rbs; String RtUv)andMerobCab;²KñaGs;BImYyeTAmYykñug Memory ehIyEpñkxag cugbMputénFaturbs; String RtUv)aneKpÞúk Character NULL b¤ ‘\0’ EdlenHCa sBaØamYyeRbIsMrab;bBaØak;fa String RtUv)anbBaØb;RtwmenH. dUecñHXøa “Cambodia” nwgRtUv)anrkSaTukkñúg Memory dUcxageRkam ³ Rby½tñ ³ PaBxusKñarvag String “A” CamYynwg Character ‘A’ KW ³ A “A” RtUv)anrkSaTukkñúg 2 Byte Memory KW ³
\0
cMENk ‘A’ vijRtUv)anrkSaTukkñúg 1 Byte Memory KW ³ A eyIgGacsresr ³ ‘A’ + ‘b’ + 5 mann½yfa 65 + 98 + 5 EteyIgBMuGacsresr ³ “A” + “b” + 5 (mankMhuseRBaH “A” nig “b” suT§EtCa String)
I.7. Tinñn½yRbePT
Boolean
Tinñn½yRbePT Boolean CaRbePTTinñn½ysMedAeTAelIEttMélBIrb:ueNÑaH KW 1 nwg EdlenHCatMéltkátMNageGaylT§plrbs;sMeNIrmYy Bit (TRUE) b¤ minBit (FALSE). ]TahrN_ sMeNIr 5 < 1 enaHlT§pl = FALSE b¤ 0 5 > 1 enaHlT§pl = TRUE b¤ 1
34
0
eyagtam]TahrN_xagelIeyIgeXIjfa cMnYnKt;EdlGacmanEtBIrtMélb:ueNÑaHKW 0 nig 1. II.cMnYnefr
nig Gefr II.1. cMnYnefr
lT§plrbs;sMeNIrxagelIKWCa
(Constance & Variable)
enAkñgú karsresrkmμvFi I eKeRbIcMnYnefredIm,ICyY sMrlY eGaymanPaBgayRsYl kñúgkareRbItMél Cak;EsþgNamYyEdlnwgBMuRtUv)anERbRbYlkñúgdMeNIrkarénkmμviFI. eyIgGackMNt;eQμaHNamYy edIm,ItMNageGaytMéléncMnYnefrRbePTNamYy edayeRbIBaküKnøwH const BIxagmux. ]TahrN_dUcCa ³ const int a = 300; const float b = 3.50; const char ch = ‘A’, k = ‘5’;
eRkaykarRbkasdUcxagelI eBlenHeyIgTTYl)an ³ a CacMnYnefrRbePT integer EdlmantMél 300 b CacMnYnefrRbePT float EdlmantMél 3.50 ch nig kCacMnYnefrRbePT charEdlmantMél ‘A’ nig ‘5’ eRkayeBlRbkasbNþaeQμaHxagelIenHCacMnYnefrrYc enaHeyIgnwgBMuGac nwgeFVIRbmaNviFINamYy EdlbNþaleGaymankarERbRbYldl;tMélrbs;cMnYnefr TaMgenaHLIy. TMrg;énkarRbkascMnYnefr ³ const RbePTTinñn½y
eQμaHcMnYnefr = tMéléncMnYnefr
II.2. Gefr
enAkñúgPasasresrkmμviFIkMuBüÚT½r GefrKWCaeQμaHénbNþMú Memory (cab;BI Address NamYyeTA) EdlRtUv)aneKeRbIsMrab;rkSaTukTinñn½yRbePTNamYyenAkñúg Memory énkMuBüÚT½r. 35
Tinñn½yTaMgGs;suT§EtmanRbePTrbs;va dUecñHedIm,IeRbIGefr sMrab;púÞkTinnñ ½yRbePTNamYyenaH CadMbUgeyIgRtUvRbkasGefrenaHCamYyRbePT Tinñn½yEdlnwgRtUvpÞúkCamunsin. rebobRbkasGefr RbePTTinñn½y Gefr1, Gefr2, …, Gefrn; ]TahrN¾ ³ int m,n ; float x ;
eRkayeBlRbkasdUcxagelI eBlenHeyIgTTYl)an m nig n KWCaGefr RbePT int dUecñHeyIgGacyk m nig n eRbIedIm,IpúÞkTinnñ y½ RbePT int )an. cMEnkÉ x vijRtUv)anRbkasCamYy float dUecñHeyIg)anvaCaGefrRbePT float EdlGac eRbIsMrab;pÞúkTinñn½yRbePT float )an. III. RbmaNviFI III.1. bNþasBaØaEdleRbIkñúgRbmaNviFInBnþ
sBaØa + * / %
sBaØa
/ +
Gtßn½y
bUk dk KuN Eck EckyksMNl;
]TahrN¾ a+b a-b a*b a/b a%b
³ RbsinebIEckelxrvagBIrcMnYnKt; enaHeyIgnwgTTYl)anplEckCa cMnYnKt;.
36
]TahrN_ ³
10/3 = 3 (lT§plKW 3BMuEmn 3.333 eT)
ebIEckelxrvagcMnYnBit nwgTTYl)anplEckCacMnYnBit. ]TahrN¾ ³ +
10.00/3 10/3.0
sBaØa
nigcMnYnBit
b¤cMnYnBit
nigcMnYnKt;
enaHeyIg
= 3.333333 = 3.333333
³ enHKWCasBaØaEckyksMNl; vaRtUv)anGnuvtþEtelIkarEckcMnYnKt;CamYy cMnYnKt;b:ueNÑaH. ]TahrN_ ³ %
10%3 = 1 10.0%3 krNIenHmankMhus
kmμviFI]TahrN_ ³ kmμviFIxageRkamenHCa]TahrN_bgðajGMBIkareRbIsBaØaEckykplEck kareRbIsBaØaEckyksMNl;. kmμviFI Prog2_2.C #include<stdio.h> #include<conio.h> void main() { int a, b; /*--- RbkasGefr a nig b CaGefrRbePT int ---*/ float x; /*--- RbkasGefr x CaGefrRbePT float ---*/ a = 10 ; b = 3; x = a/b; /*--- EckcMnYnKt; a eGay b ---*/
clrscr(); /*--- lubbNþaGkSrEdlkMBugmanelIeGRkg; ---*/ printf("x = %f",x); /*--- bgðajtMél x elIeGRkg; ---*/ x = 10.0/3; /*--- EckcMnYnTsPaK 10.0 eGay 3 ---*/ printf("\nx = %f",x);
37
nig
x = a % b; printf("\nx = %f",x); a = 20 % 7; /* EckyksMNl; ehIyP¢ab;lT§pleGay a */ printf("\nA = %d",a); getch(); /*--- rg;caM Press Key NamYy ---*/ }
lT§plelIeGRkg;KW ³ x = 3.000000 x = 3.333333 x = 1.000000 x=6
III.2. GaTiPaBkñúgRbmaNviFInBnþ
enAkñúgkareFVIRbmaNviFInBVnþ karKNnaRtUvcab;ecjdMeNIrBIeqVgeTAsþaM nigsBaØaRbmaN viFInImYy²GacmanGaTiPaBepSg²Kña dUcCa RbmaNviFIbUk nigdk KWmanGaTiPaBesμIKña k¾b:uEnþvaRtUvTabCagGaTiPaBrbs;RbmaNviFIKuN Eck nigEck yksMNl; (EtRbmaNviFITaMgbI enHmanGaTiPaBesμIKña). kñúgkenSammYy vaGacmankareFIVRbmaNviFIeRcIn ehIyRbmaNviFInImYy² GacmanGaTiPaBepSg²Kña dUecñHkñúgkenSamenaHnwgRtUvmanRbmaNviFIxøH)anGnuvtþ mun nigxøHeTotRtUvGnuvtþtameRkay. ]TahrN¾karKNnakenSam ³ 5+10/3 lT§plénkarKNnakenSamxagelIenHKW 8 BIeRBaHsBaØaEckmanGaTiPaB x<s;CagsBaØabUk dUecñHRtUvGnuvtþRbmaNviFIEckmun )anlT§plehIyeTIbGnuvtþ RbmaNviFIbUktameRkay. edIm,IeCosvagkMhuskñúgRbmaNviFI b¤kñúgkenSamRbmaNviFI enaHeyIgRtUv eRbIsBaØargVg;Rkck ( ) edIm,IbBaØak;GMBIGaTiPaBénRbmaNviFI. ]TahrN_dUcCa ³ (5+10)/3 eyIg)anlT§plKW 5 38
5+(10/3)
eyIg)anlT§plKW 8
III.3. RbmaNviFIeRbobeFob
nig RbmaNviFItká lT§plrbs;RbmaNviFeI RbobeFob nigRbmaNviFItká manEtBIrtMélb:ueNÑaH KWBit b¤minBit (0) dUecñHlT§plrbs;RbmaNviFIenHCaTinñn½yRbePT Boolean.
(1)
bNþasBaØaRbmaNviFIeRbobeFob sBaØa > >= < <= == !=
Gtßn½y
]TahrN_
FMCag b¤eT? FMCag b¤esIμ b¤eT? tUcCag b¤eT? tUcCag b¤esIμ b¤eT? esIμKña b¤eT? xusKña b¤eT?
a>b a>=b a<b a<=b a==b a!=b
sBaØaRbmaNviFIdMbUgmanGaTiPaBesμIKña b:uEnþvax<s;CagGaTiPaBrbs;BIr sBaØaRbmaNviFIcugeRkay (KW == nig != ) EtkñúgenaHRbmaNviFI (==) nig (!=) manGaTiPaBesμIKñavij. RKb;bNþasBaØaRbmaNviFIeRbobeFobTaMgGs; suT§EtmanGaTiPaBTabCag bNþasBaØaRbmaNviFInBVnþ ]TahrN_dUcCakenSam m < (n-1) enaHkMuBüÚTr½ nwgGnuvtþ RbmaNviFInBVnþmunKW (n-1) rYceTIbeFVkI areRbobeFoblT§plenaHCamYy m tameRkay. 4
bNþasBaØaRbmaNviFItká ³
sBaØaRbmaNviFtI kákúñgPasa C rYmman 3 dUc)anbgðajkñúgtaragxageRkam ³
39
sBaØa
Gtßn½y
]TahrN_
bdiesFn_ (NOT) RbmaNviFI (AND) RbmaNviFI (OR)
! && ||
!a a && b a || b
xageRkamenH Catarag]TahrN_bgðajGMBIkareRbIR)as;bNþasBaØaRbmaN viFItká. a 0 0 1 1
b 0 1 0 1
!a 1 1 0 0
!b 1 0 1 0
a&&b 0 0 0 1
!(a&&b) 1 1 1 0
a || b 0 1 1 1
!(a || b) 1 0 0 0
cMNaM ³ kñúgRbmaNviFItká a nig b GacCacMnYnKt; b¤cMnYnBit bNþasBaØaRbmaNviFIeRbobeFobTaMgGs; suT§EtmanGaTiPaBTabCagsBaØa RbmaNviFI NOT k¾bu:EnþvamanGaTiPaBx<sC ; agsBaØaRbmaNviFI AND nig OR vij. ]TahrN¾kenSam (a<b)&&(c>d) eyIgGacsresr)anfa a<b&&c>d eBlenaHkareFIVRbmaNviFIelIkenSamenHKWRtUvGnuvtþRbmaNviFI a < b rYcehIyeTIb KNna c > d nigCacugeRkayeTIbyklT§plBIrRbmaNviFmI unenHeTAGnuvtþRbmaN viFI AND. xageRkamenH bgðajGMBlI Mdab;GaTiPaBkñúgRbmaNviFeI RbobeFob nigRbmaN viFItká ³ ! >> =
<<=
==
!=
&&
||
RbmaNviFITaMgenH CaFmμtavaEtgRtUv)aneKeRbIedIm,IbegáItlkçxNÐsMrab; eRCIserIskargar b¤k¾bBa©b;kargarenAkñúgrgVil (Loop) NamYy.
40
kmμvFi xI ageRkamenH Ca]TahrN_bgðajGMBrI ebobeRbIR)as;bNþasBaØaeRbob eFobxagelIenAkñúgkarsikSalkçxNÐedIm,IeRCIserIskargarmkGnuvtþ. kmμviFI Prog2_3.C #include <stdio.h> #include <conio.h> void main() { int n; printf("\nInput an integer between 0 and 10 :"); scanf("%d",&n); if(n>5) printf("\nYou entered %d which is greater than 5",n); if(n<5) printf("\nYou entered %d which is smaller than 5",n); if(n==5) printf("\nYou entered 5"); getch(); }
lT§plelIeGRkg;KW ³ Input an integer between 0 and 10 : 6
41
III.4. RbmaNviFIelI
BIT
xageRkamenHCabNþakargarEdlEtgEt)anCYbCajwkjab;enAkñúgPasakMrit Tab EtBMusUvCa)anCYbenAkñúgPasakMritx<s;eLIy. vamanmuxgarsMrab;eFVIRbmaN viFIeTAelI Bit nImYy²rbs;cMnYnKt; (bNþasBaØaRbmaNviFIxageRkamenH BMuGac Gnuvtþ)ancMeBaHRbePTTinñn½y float nig double eLIy) : sBaØa & | ^ << >> ~
Gtßn½y RbmaNviFI AND cMeBaH Bit nImYy² RbmaNviFI OR cMeBaH Bit nImYy² RbmaNviFI XOR cMeBaH Bit nImYy² rMkileqVg rMkilsþaM RbmaNviFIbdiesFn_ Bit nImYy²
]TahrN_ a&b a|b a^b a << b a >> b ~a
]TahrN_ ³ a 1 1 0 0 a << N = a*2 a >> N = aN 2 ~1 = 0 ~0 = 1
b 1 0 1 0
a&b 1 0 0 0
N
42
a|b 1 1 1 0
a^b 0 1 1 0
a). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI & ³
]bmafaeyIgmanGefrcMnYnKt;BIrKW a nig b Edl a = 5 nig b = 10 cUrKNna x = a & b ? eyIgman ³ a = 5 KW 0 0 0 0 0 1 0 1 & b = 10 KW
0
0
0
0
1
0
1
0
ª
x = a & b KW
0
0
0
0
0
0
0
0
Ö
x=0
b). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI | ³
]bmafaeyIgmanGefrcMnYnKt;BIrKW a nig b Edl a = 5 nig b = 10 cUrKNna x = a | b ? eyIgman ³ a=5:
0
0
0
0
0
1
0
1
b = 10 :
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
1
|
x=a|b: ª
x = 15
c). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI ^ ³
]bmafaeyIgmanGefrcMnYnKt;BIrKW a nig b Edl a = 5 nig b = 10 cUrKNna x = a ^ b ? eyIgman ³ a=5:
0
0
0
0
0
1
0
1
b = 10 :
0
0
0
0
1
0
1
0
^
43
0
x=a^b: ª
0
0
0
1
1
1
1
x = 15
d). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI << ³
]bmafaeyIgmanGefrcMnYnKt; a mYyEdl a = 5 cUrKNna x = a << 2 ? ()ann½yfa cUrKNna x EdlesμInwgtMél a rMkileTA xageqVgcMnYn 2 bit). ENnaM ³ GñkGacemIlesovePA Assembly EdlniyayGMBI Instruction SHL nig SHR. eyIgman ³ a = 5 KW ³ 0 0 0 0 0 1 0 1
ª
a << 2 KW ³
0
0
0
0
0
1
0
1
x = a << 2 KW ³
0
0
0
1
0
1
0
0
0
dUecñH x = 20 e). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI >> ³
]bmafaeyIgmanGefrcMnYnKt; a mYyEdl a = 5 cUrKNna x = a >> 2 ? ()ann½yfa cUrKNna x EdlesμInwgtMél a rMkileTA xagsþaMcMnYn 2 bit. eyIgman ³ a = 5 KW ³ 0 0 0 0 0 1 0 1 a >> 2 KW ³ ª
x = a >> 2 KW ³
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
1
44
dUecñH x = 1 f ). ]TahrN_Cak;EsþgGMBIkareRbIRbmaNviFI ~ ³
ª
]bmafaeyIgmanGefrcMnYnKt; a mYyEdl a = 5 cUrKNna x = ~a ? eyIgman ³ a = 5 KW ³ 0 0 0 0
0
1
0
1
x = ~a KW ³
1
0
1
0
1
1
1
1
dUecñH x = 250 III.5. GaTiPaBrbs;bNþasBaØaRbmaNviFI
enAkñúgkenSamKNna faenAkñgú kenSamenaH viFINamYyepSgeTot. dUckñúgtaragxageRkam ³ lr
sBaØaRbmaNviFInImyY ²GacmanGaTiPaBepSgKña )ann½y GacmansBaØaRbmaNviFINamYyRtUv)anGnuvtþmnu sBaØaRbmaN lMdab;GaTiPaBrbs;bNþasBaØaRbmaNviFIRtUv)anbgðaj bNþasBaØaRbmaNviFI
1
()[]->.
2
! ~ & * - ++ -- (type)sizeof
3
* / %
4
+ -
5
<< >>
6
< <= > >=
7
== !=
45
lMdab;RbmUlpþMú BIeqVgeTAsþaM BIsþaMeTAeqVg BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM
8
&
9
^
10
|
11
&&
12
||
13
?:
14
= += -= *= /= %= <<= >>= &= ^= |=
15
,
BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM BIeqVgeTAsþaM BIsþaMeTAeqVg BIsþaMeTAeqVg BIeqVgeTAsþaM
ENnaMbEnßmGMBIkaremIltaragxagelI ³ 1. bNþasBaØaRbmaNviFx I agelIEdlsresrenAelIbnÞat;EtmYy enaH)an n½yfamanGaTiPaBesμ²I Kña nigbNþasBaØaEdlfitenAbnÞat;xagelI manGaTiPaBCag bNþasBaØaEdlfitenAbnÞat;xageRkamva. 2. cMeBaHbNþasBaØaEdlmanGaTiPaBesμIKña lMdab;énkarKNnaGaccab; epþImBIeqVgeTAsþaM b¤BIsþaMeTAeqVgvij dUc)ancg¥úlbgðajenAkñúgkUeLan {lMdab; RbmUlpþMú}. ]TahrN_dUcCa ³ + cMeBaHkenSam * --px eyIgeXIjfa sBaØa * nigsBaØa -- man GaTiPaBesμKI añ k¾b;uEnþlMdab;énkarKNnaKWBsI aþ MeTAeqVg. dUecñHRtUvKNna --px rYceTIbyklT§plEdlTTYl)aneTAeFVIRbmaNviFIKuNtameRkay. + cMeBaHkenSam 8/4*6 eyIgeXIjfa sBaØa / nigsBaØa * man GaTiPaBesμIKña k¾b:uEnþlMdab;énkarKNnaKWBIeqVgeTAsþaM. dUecñHmann½yfa RtUvKNna 8/4 rYceTIbyklT§pl 2 EdlTTYl)anenaHeTAeFVRI bmaNviFKI uN CamYy 6 dUecñHlT§plrbs;kenSam 8/4*6 KW 12. 3. edIm,IsresrkenSameGay)anRtwmRtUvbMput enaHRtUveRbIsBaØargVgR; kck 46
III.6. karbegáIn
nig karbnßaytMélrbs;Gefr C )anpþlB ; rI RbmaNviFmI Yy Operand edIm,IeFVkI arbgánI b¤bnßytMélrbs;Gefr (TaMgcMnnY Kt; nigcMnYnBit). karI ++ eRbIsrM ab;bkU tMél 1 bEnßmeGayeTAelI Operand cMEnkÉkarI -vijKWsMrab;dkyktMél 1 ecjBI Operand EdlenACab;vaenaHvij. ]TahrN_fa eyIgmanGefr n EdlkMBugpÞúktMélesμI 5 enaHeyIg)an ³ ª eRkayRbmaNviFI ++n enaH n nwgTTY)antMél 6 ª eRkayRbmaNviFI --n enaH n nwgTTY)antMél 4 karI ++ nig -- GacQrenAxagmux Operand b¤k¾xageRkay Operand k¾b:uEnþ lT§plEdlTTYl)anmanPaBxusKñabnþic. dUecñHeyIgGacsresr ³ ++n
n++
--n
n—
PaBxusKñarvag ++n nig n++ KW ³
kñúgRbmaNviFI n++ (Postfix) enaHtMél n nwg RtUv)anekIneLIgEfm mYytMéleTot eRkayeBltMélcas;rbs; n RtUv)aneKeRbIR)as;rYc. + cMENkÉ ++n (Prefix) vijenaH tMélrbs; n nwgRtUv)anekIneLIgmYy tMéleTot TaMgmuneBltMélcas;rbs;vaBMuTan;RtUv)aneKeRbIR)as;enAeLIy. ]bmafaeyIgmanGefr n EdlkMBugpÞúktMél 5 enaHeyIg)an ³ x = n++ ; /*P¢ab;tMél 5eGayeTA x bnÞab;mk n TTYl)antMél 6 */ cMENkÉ ³ x = ++n ; /*n TTYl)antMél 6 rYck¾P¢ab;tMél 6 enaHeGayeTA x */ cMeBaHkarI -- vijk¾dUcKñaCamYykarI ++ xagelIEdrRKan;EttMélrbs; Operand RtUv)andkecjmYytMélb:ueNÑaH. eRkAGMBIRbmaNviFIxagelIenH kñúg C enAmankarImYycMnYneTotsMrab;Gnuvtþ RbmaNviFIdUcCa ³ n=n+5; Gacsresr n += 5; m=m-5; Gacsresr m -= 5; +
47
x = x *(y + 5) ; z = z /(a + b) ; y=y%a;
Gacsresr x *= y+5; Gacsresr z /= a+b; Gacsresr y % = a;
karIesμI = karIesμI RtUv)aneKeRbIsMrab;Pa¢ b;téM lrbs;kenSamxagsþaMkarW eGayeTA kenSamEpñkxageqVgkarI. eyIgGaceRbIkarIesμsI Mrab;P¢ab;tMéleGayGefrdUcTMrg; xageRkam ³ a = b = c = 5; Ö eyIgTTUl)an
a=5
b = 5 nig c = 5
eyIgk¾GacP¢ab;tMéleGaybNþaGefrdUc]TahrN_xageRkamenH ³ int x, y, z; /* RbkasGefr */ z = (y = 3) * (x = 5); Ö eyIgTTUl)an x=5 y=3 nig z = y * x = 3 * 5 = 15
dUecñHeyIgTTYl)an z = 15 III.7. kenSamlkçxNÐ
Conditional Expression
kenSamlkçxNÐCakenSamEdlmanTMrg;dUcxageRkam ³ e1 ? e2 : e3 kñúgenaH e1, e2
nig e3 KWkenSamepSg²Kña. tMélrbs;kenSamlkçxNÐenHnwg esμI e2 RbsinebIkenSam e1 Bit EtpÞúyeTAvijvanwgTTYlyktMélrbs;kenSam e3. RbsinebI e2 nig e3 CaRbePTcMnYnKt; enaHtMélrbs;kenSamTaMgmUlk¾CacMnYnKt; Edr EtebI e2 b¤ e3 CacMnYnBitenaHtMélrbs;kenSamk¾manRbePTCacMnYnBitEdr. ]TahrN¾ x = (a > b) ? a:b
48
nwgTTYl)antMélesμI TTYl)antMélesμI b. x
a
RbsinebI
a > b
EtebIpÞúyeTAvijenaH
printf(“\n%f”, a<b?a:b); Statement xagelIenHmanmuxgarbgðajelIeGRkg;nUvtMélmYyEdlCatMél
x
nwg
Gb,rimarvag
a
nig b. kmμvFi xI ageRkamenHCa]TahrN_bgðajGMBrI ebobeRbIkenSamlkçN.Ð CadMbUg kmμviFIdMrUveGayGñkeRbIbBa©ÚltMéleGayGefr n bnÞab;mkeTIbbBa©ÚleGayGefr m rYcehIyeTIbbgðajtMélGtibrimarvagtMél n nig m. kmμviFI /*Prog2_4.C*/ #include <stdio.h> #include <conio.h> void main() { int n, m, max; printf("\nInput n="); scanf("%d",&n); /* bBa©ÚltMéleGayGefr n */ printf("\nInput m="); scanf("%d",&m); /* bBa©ÚltMéleGayGefr m */ max = (m>n)?m:n; /*
eRbobeFobemIletI m FMCag n b¤eT
*/ printf("\nMax = %d",max); getch(); }
lT§plelIeGRkg;KW ³ Input n = 10 Input m = 20 Max = 20
49
III.8. karbþÚrRbePTTinñn½y
Casting Data Type
kñúgeBleFVIRbmaNviFI karbþÚrRbePTTinñn½yeRcInEtekItmaneLIgedaysV½y RbvtþidUcCa³ enAeBlEdlkñúgkenSammaneRcInFatu ehIyFatunImYy²manRbePT Tinñn½yepSgKña. enAeBlEdlP¢ab;tMélRbePTNamYyeGayeTAGefrRbePTepSg Edl krNIenHEtgekItmaneLIgkñúgeBlP¢ab;tMéleGayeTAeQμaH Function edayBakü KnøwH return b¤ k¾epÞrtMélBI Argument eGayeTA)a:ra:Em:Rt nigkñúgkrNImYycMnYneTot. CamYyKñaenHEdr kñúgeBleFVIRbmaNviFI eyIgk¾GacbþÚrRbePTTinñn½yBIRbePT mYyeTACaRbePTmYyepSgeTot edaysresrtamTMrg;dUcxageRkam ³ (Data type) kenSam
]TahrN¾ ³ (float)(a+b)
karbþÚrRbePTTinñn½ykñúgkenSam EtgEtekIteLIgedaysV½yRbvtþienAeBlEdl bNþaFatuenAkñúgkenSam manRbePTTinñn½yepSgKña ehIyenAeBlenaHRbePT Tinñn½yEdlmanTMhM Memory tUcCag nwgRtUvbþÚreTAtamRbePTTinñn½yrbs;Fatu EdlFMCag. ]TahrN¾dUcCa eyIgeFIVRbmaNviFI a+b EdlkñúgenaH a manRbePT Tinñn½yCa int cMEnk b manRbePTTinñn½yCa long dUecñHeBleFIVRbmaNviFIenH a nwg RtUv)anbþÚredaysV½yRbvtþieTACaRbePT long (BIeRBaH int manTMhM Memory 2 byte tUcCag long EdlmanTMhM Memory rhUtdl;eTA 4 byte). eyIgGacbþÚrRbePTTinñn½yBIRbePTmYy eTACaRbePTmYyeTotepSgeTot)an dUcbNþa]TahrN_xageRkamenaH ³ int a, b, x; float y, z;
50
a = 10; /* P¢ab;tMéleGayGefrcMnYnKt; a = 10 */
P¢ab;tMéleGayGefrcMnYnKt; b = 3 */ = a/b; /* eyIgTTYl)an x = 3 eRBaHkñúgkrNIEckcMnYnKt;eGaycMnYnKt; enaHeyIgnwgTTYl)anlT§plCacMnYnKt; */ = a/b; /* eyIgTTYl)an y = 3.000 eRBaHEckcMnYnKt;eGaycMnYnKt;enaH eyIgnwgTTYl)anlT§plCacMnYnKt; */ = (float)a/b; /* eyIgTTYl)an y = 3.333333 eRBaHeBlenHcMnYnKt; a RtUv)anbMElgeTACaRbePTcMnYnBit dUecñHkenSam y enaH)ann½yfa EckcMnYnBiteGaycMnYnKt; Ö lT§plEdlTTYl)anRtUvEtCacMnYn Bit (cMnYnTsPaK) */ = (float)(a/b); /* TTYl)an y = 3.000 eRBaH a/b )anlT§plCacMnYnKt;KW 3 rYcehIyeTIbbMElglT§plenaHeTACaRbePT float )anCa 3.00 ehIyP¢ab;eGay y Etmþg. */ = (float)(a/b); /* eyIg)an x = 3 BIeRBaHlT§plénkarEckKWCacMnYnKt; 3 bnÞab;mkbMElgvaeTACaRbePT float dUecñHlT§plenaHkøayeTACa 3.00 ehIyP¢ab;eGayeTA x. EtedayGefr x manRbePTCa int dUecñHlT§plenaHRtUv)anbþÚrRbePTedaysV½yRbvtþieTACaRbePT cMnYnKt; (int) */
b = 3; /* x
y
y
y
x
z = 5.00; x = a/z; /* lT§plKW x = 2 */
IV. Statement
kMNt;bNþakargarEdlkmμviFIRtUvGnuvtþn¾edIm,IKNnabNþaTinμn½yEdleyIg)an declaration . manBIr y:agKW statement eTal nig statement manTMrg; ³ + Statement eTalCa statement EdlKμanpÞúkbNþa statement epSgeTot. dUcCa Assignment ( a = 2 ) . Statement
51
man structure : Ca statement EdlmanpÞúkbNþa statement epSgeTotkñúgva . dUcCa for.., while .., do ... while; . kúñg Turbo C cugbBa©b;én statement nImYy²RtUvmansBaØa + Statement
Semi colon (;) Ex: x = 2; y = 3 < 5* 8;
Z=PI;
=====*=====
52
sMNYr 1. 2. 3. 4.
cUrniyayGMBIPaBxusKñarvag Character ‘\0’ nig ‘0’ ? cUrniyayGMBIPaBxusKñarvag “A” nig ‘A’ ? etIGefr nigcMnYnefrKWCaGVI? nigRtUv)aneKeRbIsMrab;eFVIGVI? cUrkMNt;tMélrbs;kenSamxageRkam ³ x1 = 10%3 x2 = 10/3 x3 = 10/3.0 x4 = 10.0/3 x5 = 10.0/3.0
5.
cUrkMNt;tMélkenSamxageRkam ³ a). b).
6.
cUrKNnakenSameRbobeFobxageRkam ³ a). b). c).
7.
5.6 + 2.7 + 20/6 + 8.0 5.6 + 2.7*20/6 - 8 x1 = (6+5*3/2) <= (7/4*2+10/4) x2 = (6+5*3/2) == (7/4*2+10/4) x3 = (6+5*3/2) != (7/4*2+10/4)
cUrKNnaRbmaNviFIxageRkam ³ a = 10; b = 5; c = 7; x = (((a+b) <= (a-c)) || (a+b+c) >= 1000) y = (!(a+b) <= 4 || (a-c) > 2) && (a+b+c < 100)
8.
cUrkMNt;tMélrbs;bNþakenSamxageRkam ³ x1 = 10 & 5 x2 = x1 | 25 – 5 x3 = x1 ^ x2 x4 = (10 << 2) + (20 >> 4)
9.
cUrbgðajbNþakenSamEdlmanlkçN³RtwmRtUv ³ a). c).
(i = j)++ ++(i+j)
b). d).
53
i+j++ ++i+++j