You are on page 1of 46

‘C’ Language

The ‘c’ Programming language was introduced by “Dennis Ritchie” in “At and T” Bell laboratories in early 19 !’s"

‘#’$#%&P'()R* $
A ’c’ +rogram has been con,erted in to the &achine language be-ore e.ecution" A ‘c’ #om+iler translates a ‘c’ +rogram in to a &achine language"

PR)$PR%#)//%R* $
Be-ore com+ailing a #$+rogram a +rocess called Pre$Processor is done on the source board by the +rogram called Pre$Processor" 0nderstanding this +rocess will hel+ us “1 include 2stdio"h3”" This line is a +re$+rocessor Directory"The +re$+ocessor +rocess the # +rogram be-ore the com+ailer "All (ines in the +rogram beginning with the hash 415 sign are +rocessed by the Pre$+rocessor"The 1 include directi,e causes the Pre$+rocessor to e--ecti,ely insert the stdio"6 by into the #$Program" 7hen the #om+ailer com+iles the +rogram8 it seems the conte.ts o- the stdio"h -ile inserted into the Pre$+rocessor ,alue -ollowed by the rest o- the +rogram" 9ollowing are the +re +rocessor directi,es* 1de-ine 1include 1i1else 1unde1+rogma 1 de-ine*$ 1de-ine is used to ma6e macro de-inition in a ‘c’ +rogram" ).* 1 de-ine &A: 1!! ;ere we de-ine a constant ma. with its ,alue 1!!" 7hene,er a +rogram encounted &A: it is re+laced to 1!!" 1include*$

-1 -

‘C’ Language
This is used to include the header -iles containing the -unction to be used in the -unction" 1include2stdio"h3 This will include the stdio"h -ile -rom the include directory" ).am+le +rogram 1include2stdio"h3 1include2conio"h3 main45 < clrscr45= +rint-4>7elcome To #>5= getch45= ?

@AR'AB()/ AAD ):PR)//'%A/* $
#;ARA#T)R /)T* $ The ‘#’ character set consists o- u++er and lower case Al+habets8 Digits8 /+ecial #haracters and 7hite /+aces" The Al+habets and Digits together called as al+hanumeric characters" Al+habets * ABBB"C aBBB""D Digits * !BB"9 /+ecial characters * comma8 +eriod8 ash" 7hite s+ace characters * blan6 s+ace8 Aew line"

'D)AT'9')R/*$
'denti-iers as the name suggests are used to identi-y or name ,ariables8 /ymbolical constants8 -unctionsBetc" There are some rules regarding identi-iers names as -ollows*$ 415 'denti-ier name must be a seEuence o- digits or letters and must begins with a letter" 4F5 The underscore 4 G 5 symbol is considered as a letter" 4H5 Aames shouldn’t be the same as 6ey words"

-2 -

‘C’ Language

I)J 7%RD/*$
Iey words ha,e +re$de-ined meanings and cannot be changed by the user" Iey words are +re$de-ined by the language and cannot be used by the user in any way" The -ollowing 6ey words are +re$de-ined by the language" Auto int -or e.term Brea6 long int while switch #ase long goto else #har i-loat do BBBB etc are some o- the +re$de-ined 6ey words in ‘c’"

@AR'AB()/*$
A ,ariable is an antity that has the ,alue and is 6nown to the +rogram by a name" A ,ariable decision associates a memory location with the ,ariable name" A ,ariable can ha,e only one ,alue assigned it at any gi,en time during the e.ecution o- the +rogram" @ariable names are identi-iers used to the name ,ariable" A ,ariable name consists oseEuence o- letters and digits" The -irst character must be a letter"

BA/'#$ DATA TJP)/*$
The ‘c’ language su++orts the -ollowing Data ty+es" #har * A single byte that holds a character" 'nt * An 'nteger" 9loat * ;olds a -loating +oint number" Double * A double +recession -loating +oint number" RAAK) %9 DATA TJP)/*$ 'nteger 0n$signed int (ong int #haracter 0n$signed char 'nteger 9loat 9loat range #har Double

*$ *$ *$ *$ *$ *$ *$ *$ *$ *$

HF LM$HF L " !$LNNHN" F1O MHLO $F1O OMHLO " 1FM$1FM" !$FNN" F Bytes" O Bytes" $H"Oe $HM$H"OePHM 1 Byte" M Bytes"

-3 -

‘C’ Language
Double range :1.7e-308-1.7e+308.

A(K%R'T;&*$
An Algorithm is a -inite set o- roots -or sol,ing a s+eci-ic ty+e o+roblems" 4or5 Algorithm is nothing but the ste+ by ste+ +rocess o- a +rogram" /TR0#T0R) %9 A(K%R'T;&*$ Algorithm consists o- -ollowing ste+s* /te+ 1 *$ 'n$+ut" /te+ F *$ Assignment ste+" /te+ H *$ Decission ste+" /te+ O *$ Re+itati,e ste+" /te+ N *$ out$+ut"

9(%7 #;ART*$
A -low chart is a +ictorial diagram to sol,e a +articular +rogram" 't is a diagrammatic re+resentation that illustrates the seEuence oo+erations to be +er-ormed to arri,e the solutions" The o+erating instructions are +laced in bo.es8 which are connected by arrows" /J&B%(/*$The symbols are*$ %,al Rectangle Parallelogram Rhombus /tartQ/to+" Processing Bo." 'n+ut Q %ut +ut" Decisions bo."

#ircle

#onnector"

%P)RAT%R/ AAD ):PR)//'%A/$
There are /e,en ty+es o- %+erators *$ i" Arthematic %+erator"

-4 -

i" Bit$7ise %+erator" .unary P" $ /ubstraction o.the arthematic o+eratirs we can see the other o+erator +rograms4$8R8Q8S5 R)(AT'%AA( %P)RAT%R*$ These are used to com+are arthematic8 logical and character e.+ressions" %P)RAT%R/*$ 2 (ess than" 3 Kreater than" 2T (ess than or )Eual to" 3T Kreater than or )Eual to" R -5 - ." Assignment %+erator" .am+le -or Arthematic o+erator 4addition5*$ 1include2stdio"h3 main45 < int a8b8cT!= +rint-4>)nter Two Aumbers aUb*>5= scan-4>SdSd>8Ua8Ub5= cTaPb= +rint-4>aPb 's Sd>8c5= getch45= ? /imilarly by changing the symbols o.‘C’ Language ii" Relational %+erator" iii" (ogical %+erator" i.)&AT'# %P)RAT%R*$ The Arthematic o+erator +er-orms arthematic o+erations and can be #lassi-ied in to unary and Binary Arthematic %+erations" %P)RAT%R/*$ P Addition o." #onditional %+erator" .ii" #omma %+erator" ART.unary $ " &ulti+lication" Q Di.ision" ).ision" S &odulo Di.

the e.+ression is one o.a is !!!! !!!! !111 B'T$7'/) AAD*$ Bit wise AAD %+erator aUUb" -6 - .aluates to true only i.+ression e.‘C’ Language TT )Eual to" VT Aot eEual to" (%K'#A( %P)RAT%R*$ 't is used to com+are or eEualate logical and relational e.‘m’ or ‘n’" (%K'#A( A%T*$ The not o+erator ta6es single e.‘a’ is less than o.a is !!!! !!!! 11!1 Binary re+resentation o.TT!"The whole e.aluates to true ithe e.both o.TT! The e.the .aluates the -alse i.+ression on the right .alue o.+ression is true" B'T$7'/) %P)RAT%R*$ 't o+erates each +rint o.TT! 7hole e.both e.+ression is -alse8 e.them is true8 or i.them are true8 i"e" i.+ression and e.Data" These o+erators are used -or testing8 #om+lementing or shi-ting bits to the right or le-t" UU Bit wise AAD" WW Bit wise %R" X Y 22 33 Bit wise :%R" Bit wise #om+lement" /hi-t (e-t" /hi-t Right" ):A&P()*$ AT1H8 BT " Binary re+resentation o.+ressions" There are three logical %+erators in ‘c’" i" (ogical %R" ii" (ogical AAD" iii" (ogical A%T" (%K'#A( AAD*$ #onsider the -ollowing distribution" a3b UU .+ressions are true" (%K'#A( %R*$ #onsider the -ollowing distribution" a3b WW .+ression on the le-t is ‘a’ is greater than ‘b’" The e.

er the corres+onding bits in aXb di--er" a T !!!! !!!! 11!1 b T !!!! !!!! !111 cTaXb T !!!! !!!! 1!1! /.+ression on right8 and assigns the .alue got by com+lementing each bit o.ely used in “-or U while “loo+s" The synta.‘c’ a-ter the e.'9T R'K.%+erators is gi.am+le consider the statement cTa22H" The .‘C’ Language a T !!!! !!!! 11!1 b T !!!! !!!! !111 cTaUUb T !!!! !!!! !1!1 B'T$7'/) %R*$ The statement aWWb" a T !!!! !!!! 11!1 b T !!!! !!!! !111 cTaWWb T !!!! !!!! 1111 B'T$7'/) :%R*$ The statement aXb a-ter this statement is e.‘a’ is !!!! !!!! 11!1" The .es the .ariable on the le-t8 the assignment o+erators are* T8 $T8 PT8 QT8 RT " 'A#R)&)AT $ D)#R)&)AT %P)RAT%R*$ These are e.e statement is !!!! !11! 1!!! " /.ecution oabo.ae below" -7 - .aluates the e.tensi. o.ected8 a bit in c will be when e.‘c’ a-ter the e.e statement is !!!! !!!! !!11" B'T$7'/) #%&P()&)AT *$ 't is a unary o+erator" 't gi.alue in integer ‘a’ is shi-ted to right by F bit +osition" The result is assigned to integer ‘c’" The .am+le consider the statement cTa33F" The .ecution oabo.T %P)RAT%R*$ The Right shi-t o+erator is also a binary o+erator" 9or e.o+erator" ART.)&AT'# A//'KA&)AT %P)RAT%R*$ This %+erator e.‘a’ is !!!! !!!! 11!1" The .alue o.'9T ()9T %P)RAT%R*$ The le-t shi-t o+erator is a binary o+erator" 9or e.alue in integer ‘a’ is shi-ted to le-t by H bit +osition" The result is assigned to integer ‘c’"The .alue to .alue o.alue o.alue o.

t ).+ression 1 #onditional %+erator" /TR0#T0R)*$ is text exp T Conditional exp takes value exp 1 F conditional exp takes exp 2 +rogram*$ 1include2stdio"h3 main4 5 < int i8\8large= +rint-4“enter .two symbols 4Z And *5 [uestion and coloumn" /JATA:*$ Te.e.‘C’ Language PP4@ariable name5 'A#R)&)AT $$4@ariable name5 4@ariable name5PP D)#R)&)AT 4@ariable name5 The o+erator PP ads %ne and $$ /ubstracts %ne" #%AD'T'%AA( %P)RAT%R*$ The conditional o+erator consists o.a Triangle" 1include2stdio"h3 -8 - .alue -or i8\”5 = scan-4“SdSd”8Ui8U\5 = largeTi3\Zi*\ = +rint-4“large .alid construct in the c$language" ).+ression" ).+ressions se+arated by comma’s is .+ression F largeT i 3\ Z i*\ ).*$ i8\ are declared by the statement" int i8\= +rogram*$ Area o.alue is Sd”8large5 = ? #%&&A %P)RAT%R*$ A set o.

ed data ty+es" 7e can read int8 -loat8 char8 e.F8B""5= 4iii5" Kets4 5= *$ The +ur+ose o.18 U.in+ut statement is used -or reading mi.ed ty+e data" 9or this +ur+ose some standard in+ut -unctions are used" They are i" get char4 5= ii" scan-4 5= iii" gets4 5= i.the gets statement is to read a string" 't will read a string until you +ress enter 6ey -rom the 6ey board" 't will mar6 null -9 - .= .the triangle is Sd”8area5= ? 'AP0T /TAT)&)AT/*$ 'n+ut statements are used -or reading integer8 character8 string and mi. is char .‘C’ Language main4 5 < -loat b8h8area= +rint-4“)nter .character ty+e " The synta.alue -or b8h”5= scan-4“SdSd”8Ub8Uh5= areaT4bRh5QF= +rint-4“Area o.AR4 5= *$ This -unction is used -or reading a single character -rom the 6eyboard" The . * /can-4“control string 58 U.T get char4 5= 4ii5" /can-4 5= *$ The scan.ariable in which you want to store a single character should be o." getche4 5= 4i5" K)T #.ha8 decimal8 octaBBetc" by using it" 'ts control codes are -ormat codes" synta.

4 5= *$ The +rint.‘C’ Language character in the memory at the end o.+ut char statement is to dis+lay a single character on the screen" synta.ariable" synta.5= 7here . is the .4 5= +ut char 4 5= *$ +ut char is an out +ut statement" The +ur+ose o.T gets4 5= here . is the string .5" get che4 5= *$ 't will store any .ariable o. * Put char 4.the +uts statement is the +rint or dis+laying a string in+uted by the gets statement" synta.ed ty+e data" These are * i" +ut char 4 5= ii" +uts 4 5= iii" +rint.statement is used to dis+lay a te.t message or a . is the string . * getche4 5= %0T P0T /TAT)&)AT/*$ %ut +ut statements are used -or writing8 dis+laying8 +rinting8 character8 string8 mi.character ty+e in which a single character data is stored" Puts4 5= *$ The +ur+ose o.ariable" 4i.the string when you +ress the enter 6ey" synta.alue stored in the . * -10 - . * Puts 4.5= . * .ariable" Print.ariable" i"e" character .alue -rom the 6ey board and also dis+lays it on the screen" synta.ere .

18 .18 .+5 /tatement 1= /ingle /tatement i-4te.F8BB5= .ariables" #%ATR%( /TR0#T0R)/ *$ #ontrol /tructures are o.ART*$ text exp is body o.+5 < /tatement 1= #om+ound /tatement /tatement F= ? 9(%7 #.three numbers 1 include2stdio"h3 main4 5 -11 - .ere .the loo+ +rogram*$ (argest o.F8B are .two ty+es "They are*$ i" Decission ma6ing control structures" i" iii" i-$else iii" switch ii" (oo+ #onstracts" i" -or loo+" ii" 7hile loo+" iii" Do$while loo+" D)#'//'%A &AI'AK #%ATR%( /TR0#T0R)/ *$ '9 /TAT)&)AT*$ /JATA:*$ i-4te.t e.t e.‘C’ Language Print-4“control string”8 .

+ression5 statement 1= else statement F= #%&P%0AD /TAT)&)AT/*$ i-4te.t e.alues “5= scan-4“SdSdSd”8Ua8Ub8Uc5= i-4bigT!5 +rint-4“a is big”5= i-4bTbig5 +rint-4“B is big”5= i-4cTbig5 +rint-4“c is big”5= +rint-4“The largest .‘C’ Language int a8b8c8big= +rint-4“)nter any three integer .alue is Sd”8 big5= < ? '9$)(/) /TAT)&)AT *$ /JATA:*$ /'AK() /TAT)&)AT *$ i-4te.ART *$ T Text exp is F -12 - .t e.+ression5 < statement 1= statement F= BBBBBB" ? else < statement 1= statement F= BBBBBBB" ? 9(%7 #.

ecuted" Also the constants in the case statement can be o.statements are to be e.isible by H”8 '5 = else +rint-4“Sd is not di.es" The switch statement is use-ul when a .eral alternati.statements among se.ariable is to be com+ared with di--erent constants and in case it is eEual to a constant a set o.char8 int data ty+es only " /JATA: *$ /witch4n5 < case 1* /tatement 1= /tatement F= Brea6= #ase F* /tatement 1= /tatement F= Brea6= BBB"= de-ault= statement 1= ? -13 - .it Program*$ 1include2stdio"h3 main4 5= int '= +rint-4“)nter .‘C’ Language Body o.alue -or '”5= scan-4“Sd”8Ui5 = i-4'SHTT!5 +rint-4“Sd is di.istatement body o.isible by H “8 '5 = ? /7'T#. /TAT)&)AT*$ A switch statement allows the user to choose a statement or grou+ o.i-$else statement ).

ART*$ Switch variable 1st Case body of 1st loop /witch .‘C’ Language 9(%7 #.de-ault (oo+ ).[uadratic ).ariableFnd case body o.Fnd loo+ body o.it -14 - .alues -or a8b8c”5= scan-4“S-S-S-”8Ua8Ub8Uc5= dTbRb$4ORaRc5= i-4aVT!5 < i-4d2 !5 6T1= else i-4dTT!5 6TF= e.+ressions* 1include2stdio"h3 1include2math"h3 main45 < -loat a8b8c8d8real8img8 r18rF= int 6= +rint-4“)nter the three .am+le*$ Roots o.

ecuted re+eatedly while an e.+ression becomes -alse8 the loo+ terminates U the control +asses on to the statement -ollowing the loo+" A loo+ consists o.‘C’ Language i-4d3!5 6TH= switch465 < case 1* +rint-4“The roots are imaginary”5= dT$d= realT$bQ4FRa5= imgTsErt4dQ4FRa55= +rint-4“The roots are”5= +rint-4“r1TS-PS-”8real8img5= +rint-4“rFTS-$S-”8real8img”5= brea6= case F* +rint-4“The roots are real and eEual”5= r1T$bQ4FRa5= +rint-4“r1TrFTS-”8r15= brea6= case H* +rint-4“The roots are real U un eEual”5= realT$bQ4FRa5= imgTsErt4dQ4FRa55= +rint-4“The roots are”5= +rint-4“r1TS-PS-”8real8img5= +rint-4“rFTS-$S-”8real8img”5= brea6= ? ? else ? +rint-4“The eEuation is linear”5= (%%P #%A/TR0#T/ *$ (oo+s in ‘c’ called as a section o.two statements" i" #ontrol /tatement" -15 - .a +rogram to be e.+ression is true " 7hen the e.

alue o.times" /JATA:*$ 9or4initialiDation= te.ecution othe statement with in the loo+" 'n this case this increment the .ecuted once be-ore e.am+le the three com+onents are iT18i2TN8iPP The -irst com+onent iT1 is e.ecutes " '.it is -alse8 the loo+ terminates U the control o.ery e.en below" 1include2stdio"h3 main4 5 < int i= -or4iT!=i2PN=iPP5 +rint-4“Sd”8i5= ? The -or 6ey word is -ollowed by three com+onents enclosed within round braces”4 5”"These three com+onents are se+arated by semicoloun4=5" 'n the abo.this e.aluated once be-ore e.ecuting the body o.t e.ecution is trans-ered to the statement -ollowing the -or loo+" The third com+onent iPP is e.+ression o.‘i’ by 1" 't is called the u+date e.the statement with in the loo+" This is called the te.the loo+" 9%R (%%P*$ 't is used while e.ecuted only once +rior to the statements with in the -or loo+" This is called initialiDation e.+ression" 'A'T'A('CAT'%A ):PR)//'%A*$ The control .ecuting the loo+ a number o.the e.e e.+ression" The second com+onent '2PN is e.+5 /tatement Qcom+ound statement= ):A&P() *$ The +rogram that dis+lays the -irst 1! multi+les o.N on a single line is gi.‘C’ Language ii" Body o.+= u+date e.+ression is true the statement with in the loo+ e.ecuted once e.ariable is initialiDed" This +art is e.the loo+" T)/T ):PR)//'%A*$ -16 - .t e.the loo+" '.ery e.ecution o.

the loo+" 9or multi+le initialiDation and u+ date e.ART*$ initialiDation T Body o.ariable is u+dated using an e.alue o.t e.‘C’ Language The .ery e.ecution o.ecuting the body o.'() (%%P*$ -17 - .+ is te.-ound true 8the body o.aluated be-ore e.+ression is e.+ is e.the loo+ is e.ariable is tested and i.the loo+ body" 0P DAT) ):PR)//'%A*$ A-ter e.aluated to see iit is true be-ore e.loo+ 0+date e.t e.+ in the -or loo+ the control is trans-erred bac6 to the -or loo+ statement" The control .+ 9 e.+ and u+ date loo+ @ariables we use the comma o+erator" ):A&P()*$ 1include2stdio"h3 main4 5 < int i86= +rint-4“'t is Nth table “5= -or4iT!=i2TF!=iPP5 < 6TiRN= +rint-4“NRSdTSd]n”8i865= ? ? 9(%7 #.it 7.+ such as 'PP and the te.ecuted other wise the loo+ is terminated" This e.ecuted the last e.the control .

g= +rint-4“)nter .statement inside the loo+ reads -18 - .erage o.n numbers RQ 1include 2stdio"h3 main4 5 < int i8nT!= -loat sumT!8a.g5= ? The -irst scan.gTsumQF= +rint-4“A.it ):A&P() *$ QR A.loo+ while exp 9 e.S.ecuted is not 6nown in ad.ance" 7hile loo+ is to+ tested loo+" /JATA:*$ 7hile4te.+5 < statement 1= statement F= BBBB"= ? 9(%7 #.t e.erage o.statement \ust be-ore the while loo+ in+uts the -irst mar6s and stores it in ‘i’" The scan.ART*$ T Body o.times the loo+ is to be e.alues ^1 to terminate “5= scan-4“Sd”8Ui5= while 4iVT$15 < sumTsumPi= nTnPP= scan-4“Sd”8Ui5= ? a.‘C’ Language The while loo+ is used when the no o.is ”8a.

ecuted re+eatedly8 then the synta.‘C’ Language the rest o.ecuted at least o!nce" /o8 the Do$while loo+ is called a bottom tested loo+" '.aluates the condition a-ter the e.t e.a single statement has to be e.+5= &0(T' /TAT)&)AT * do < statement 1= stement F= ? while 4te. is /'AK() ):PR)//'%A* do statement 1= 7hole 4te.ecution ostatement in its construct" The statement with in the Do$ loo+ are e.ecution +roceedes with the statements immediately a-ter the while loo+" 7hich in the abo.loo+ te.am+le +rogram*$ QR Aumber Palindrome RQ 1include2stdio"h3 -19 - .aluates to -alse" /o8 the while loo+ terminates and the +rogram e.e +rogram" D%$7.t e.ART*$ Body o.+5= 9(%7 #.+ is e.it e.t e.the numbers one by one when ^1 is read8 the condition in the while statement" iVT$1 e.'() (%%P*$ The Do$while loo+ e.

8n= +rint.am+le -or brea6 is similar to the switch which are used combindly in many o.our reEuirements" #%AT'A0) *$ 't is used to by +ass the remainder o.Tre.alue -or n”5= scan.R1!Rdigit= nTnS1!= ? while nVT!5= i-4numTTre.ART*$ is T Te.loo+ ).4”)nter .the current +ass through a loo+" The loo+ doesn’t terminate when a continue statement is -20 - .+ brea6 )nd o.t e.4“Sd”8Un5= numTn= do < digitTnQ1!= re.‘C’ Language main4 5 < int num8digit8re.5 +rint-4“Sd is Palindrome”8 num5= else +rint-4“Sd is not +alindrome “8num5= ? BR)AI*$ A brea6 statement terminates the loo+ U control is trans-erred to the statement immediately -ollowing the loo+" 9(%7 #.

e to -ollow the below synta.con.e number is Sd”8sum5= ? #A/T'AK A @A(0) *$ The +rocess o.* _.‘C’ Language encounted" The remaining loo+ statements are s6i++ed and com+utation +roceeds directly to the ne.two +ositi.loo+ ).+5= .alue" To cast a .am+le*$ /um o.erting one data ty+e to another data ty+e is called casting a .e number”5= continue= ? sumPTnum= ? +rint-4“/um o.e integers" 1include2stdio"h3 main45 < int iT!8num8sumT!= -or4iT!= i2N= iPP5 < +rint-4“)nter any .ART *$ #ontinue T condition 'n loo+ 9 remaining +art o.en as * 9(%7 #.t +ass through the loo+" This statement is gi.alues”5= scan-4“Sd”8Unum5= i-4num2!5 < +rint-4“'t is negati.alue we ha.P.arT`data ty+e 4e.T-loat4 5= -21 - .

T-loat41!5QH .the -unction ? ).T1!QH .o+erators will always be considered by the com+iler when e.+ression" The +recidenci o. is H"!!! .al= Return ty+e" (ocal .alue in .aluating an e.‘C’ Language e.am+le*$ 1include2stdio"h3 int cube 4int i5 9unction declaration" Parameter ty+e" < Parameter" int ret .o+erators is as shown below" 45 " R8Q P8$8S 28 38 3T8 2T8 TT8 VT UU WW V 90A#T'%A/*$ A number o.-unctions loo+ed in to a single logical unit is re-erred to as a -unction" /TR0#T0R) %9 A 90A#T'%A*$ Return ty+e -unction name4asrgs list5 < body o.TH"HHHH %P)RAT%R PR)#'D)A#)*$ The +recidenci o.ariable" ret @alTiRiRi= return ret .* .al= ? main4 5 -22 - .

alue the 6ey .alue in the return statement" The -unction can written in any data ty+e" '.‘C’ Language < int a= (ocal .ides the -ollowing in-ormation to the com+ailer" i" The name o.alue “5= scan-4“Sd”8Ua5= +rint-4“The cube o.ariable" +rint-4“)nter .the .there is no return ." /JATA:* Return ty+e -unction name 4ty+e 5= Return ty+e s+eci-ies the data ty+e o.is called -unction declaration" This is -ollowed by the -unction body" 't is com+ared o.Sd is Sd”8"a8 cube4int a55= 9unction call" ? PART/ %9 A 90A#T'%A*$ i" 9unction declaration" ii" 9unction de-inition" iii" Return /tatement" i.the .arguments8 argument ty+e U the return ty+e" Ao -unction de-inition is allowed with in a -unction de-inition" -23 - .alue returned" iii" The number and the ty+e o..the statement that ma6es u+ the -unction8 delimited by braces" The declaration U declaration must use the same -unction name8 no o.the -unction" ii" The ty+e o." 9unction #all" 90A#T'%A D)#(ARAT'%A*$ A -unction declaration +ro.e the semicoloun the -irst line in the -unction de.oid is +laced be-ore the -unction name" 9unction declarations are also called +rototy+es" 90A#T'%A D)9'AAT'%A*$ 't is similar to the -unction declaration but doesn’t ha.arguments that must be su++lied in a call to the -unction" 7hen a -unction call is encounted the com+ailer chec6s the -unction call with its declaration" A -unction declaration is has the -ollowing synta.alue o.

the +arameter enclosed with in +arenthesis8 terminated by the semicoloun 4=5" ).*$ Return ty+e 9unction name 4arguments5= 90A#T'%A R)T0RA @A(0)* $ 9unctions in ‘c’ may or may not ha.T\= else ma.SdSdSd is Sd”8a8b8c8m5= ? -24 - .‘C’ Language /ynta. -unc4int '8int \8 int 65 < int ma.alid" 90A#T'%A #A((* $ A -unction call is s+eci-ied by the -unction name -ollowed by the .a -unction doesn’t return a .= ? main45 < int a8b8c8m= +rint-4“)nter the .imum o.imum o.e return .alue8 the return ty+e in -unction de-inition and declaration is s+eci-ied as .am+le*$ &a.= i-4i3T\ UU i3T65 ma.three numbers 1include2stdio"h3 int ma.T6= return ma.alues -or a8b8c”5= scan-4“SdSdSd”8Ua8Ub8Uc5= mTma.-unc4a8b8c5= +rint-4“&a.T'= else i-4\3T65 ma.alue o.alues" '.

‘C’ Language 90A#T'%A PARA&)T)R* $ These are the means o.e data -rom the calling -unction" /imilarly when it doesn’t return a .alue the calling -unction does not recei.alue" 't e--ect there is no trans-er odata between calling and called -unctions" ''"90A#T'%A 7'T.e data -rom the calling -unction" 't this category data will be trans-er in a one$way direction" 9rom calling -unction to called -unction" '''"90A#T'%A 7'T.communication between the calling U called -unctions" They can be classi-ied in to -ormer +arameters U actual +arameters" The -ormer +arameters are the +arameters gi. ARK0&)AT/ AAD A% R)T0RA @A(0)/* 7hen a -unction has arguments it must recei.alue or by re-erence" '''" Recursi.e -unctions" '" 90A#T'%A D)#(ARAT'%A AAD PR%T% TJP)" -25 - . R)T0RA /TAT)&)AT/* 't this category data will be trans-er both the ways8 -rom calling to called -unction and called to calling -unction" AD@AA#)D 9)AT0R)/ %9 90A#T'%A/*$ '" 9unction declaration and +roto ty+e" ''" #alling -unction by .alues" '''" 9unction with arguments and with return statements" '"90A#T'%A 7'T.alues" ''" 9unction with arguments and no return . A% ARK0&)AT/ AAD A% R)T0RA @A(0)/* $ 7hen a -unction has no arguments it does not recei. ARK0&)AT/ AAD 7'T.three ty+es* '" 9unction with no arguments and no return .en in the -unction declaration U -unction de-inition" The actual +arameters8 o-ten 6nown as arguments are s+eci-ied in the -unction call" #AT)K%RJ %9 90A#T'%A/*$ The -unction categories are o.e any .

alues o.*$ Return ty+e -unction ty+e 4argument5= 'n the abo..the .e to s+eci-y the +roto ty+e declaration" /ynta. return ty+e s+eci-y the ty+e o.the -unction" The number and data ty+e o.alue" To return a .the -unction" Return ty+e o.‘C’ Language Any ’#’ -unction by de-ault returns an integer .8 int y5 < -loat abc 4int8 int5= abc 4.the calling -unction" This declaration s+eci-ies the -ollowing" Aame o.the -unction and arguments are the data ty+es o.alue" #A(( BJ R)9)R)A#)*$ -26 - .8y5= ? -loat abc4int 68 int l5 < ? ''" #A(('AK 90A#T'%A/ BJ @A(0) %R R)99)R)A#)*$ Passing the .ariables -rom one -unction to another -unction is called call by .* 1include2stdio"h3 main4 5 < int a8b8c= int +ower 4int8 int 5= cT+ower4a8b5= ? +ower int .alue other than an integer be ha.alue return by the -unction" 9unction name is the name o.the arguments" ).e synta..alues to be +assed to the -unction" The +rototy+e declaration must be s+eci-ied the declaration +art o.

ariable then such a -unction call is called as call by re-erence" '''"R)#0R/'%A &)T.a .%D*$ ).we +ass the address o.a .am+le*$ 9actorial o.ariable" /torage clauses are o.ariable indicates the allocation o.Sd is Sd”8 n8.= +rint-4“)nter the .+ressing any intity interms o.storage +lace to the .a Aumberusing Recursion" 1include2stdio"h3 main45 < int n= long int .4numTT!5 return 1= else return numR-act4num$15= ? /T%RAK) #(A0/)/*$ The storage clause o.‘C’ Language 'n a -unction call statement i.alue -or n”5= scan-4“Sd”8 Un5= nT-act4n5= +rint-4“9actorial o.5= ? long int -act4int num5 < i.is called R)#0R/'%A" 'n ‘c’ a -unction can call any -unction that has been de-ined including itsel-" Recursion*$ ).itsel.-our ty+es* i" Auto" ii" Register" iii" /tatic" -27 - .+ressing an intity in terms o.is called R)#0R/'%A" 'n ‘c’ a -unction can call any -unction that has been de-ined including itsel-" ).itsel.

" ).ecutes -aster as com+ared to a similar +rogram without register .term" A0T% @ariable*$ All .ariables" /TAT'# @AR'AB()/* $ /tatic .ariables" A +rogram that uses R)K'/T)R .ariables declared with in a -unction are A0T% by de-ault" @ariables declared A0T% can only be accessed only with in the -unction or the nested bloc6 with in which they are declared" They are created in to and destroyed when it is e..ariables " R)K'/T)R @AR'AB()* $ There are stored in the register o.ariables retain their .ariables e.‘C’ Language i.ariables are o.two ty+es* i" /tatic .ious call" i"e" the .more .ariables that are declared with in a -unction" ii" 9ile static @ariable" /TAT'# @AR'AB()/ T.ited" Aote*$ All the +rograms we are written are ta6en or treated as A0T% .ariables are accessiable only in the -ile in which they are declared" ).ariables which can be declared register are limited" '. 'A A 90A#T'%A*$ These .alues which they had be-ore returning -rom the -unction" 9'() /TAT'# @AR'AB() *$ These are declared outside any -unction using the 6eyword /TAT'#" 9ile static .the micro+rocessors" The number o.AT AR) D)#(AR)D 7'T.alues -rom the +re.am+le*$ 1include2stdio"h3 +rint count45 < static int countT1= +rint-4“countTSd”8 count5= countTcountP1= ? -28 - .ariables are declared they are treated as A0T% .

e the de-inition o.characters" Arrays are classi-ied as -ollows %ne$dimensional array" Two$ dimensional array" &ulti dimensional array" %A)$D'&)A/'%AA( ARRAJ" This is an array which as only a single row" To declare one$dimensional array we ha.the same ty+e8 and are +laced in +hysically ad\acent location" A string can be considered as seEuence o.‘C’ Language main45 < +rint count45= +rint count45= +rint count45= ? ):T)R& *$ 7hen a +rogram scans across di--erent -iles we want to ha.erage o.the array`= ).data in memory where in all data are o.ariable name_siDe o.ariable accessible to all -unctions in these -iles8 the 6ey word ):T)R& should be used be-ore the data ty+e name in the declarations in all the -iles where it is accessed e." Data ty+e argument _siDe`= /ynta.ariables de-initions can occur in one -ile only " ARRAJ/*$ An array is a seEuence o.these -iles ha.ce+t one" The lin6er reEuires that only one o.A Aumbers" 1include2stdio"h3 main45 < -29 - .e a global .am+le*$ A.e to use the -ollowing synta.the identi-iers" Klobal .* return ty+e .

g= +rint-4“)nter the range o.* Data ty+e array name _rows`_columns`= ).the matrices A>5= -or4iT!= i2 m= iPP5 -or4\T!= \2 n= \PP5 < scan-4>Sd>8Ua_i`_\`5= ? -30 - .gTsumQn= +rint-4“a.the array”5= scan-4“Sd”8Un5= +rint-4“)nter the . addition using arrays 1include2stdio"h3 main45 < int i8 a_1!`_1!`8 b_1!`_1!`8 c_1!`_1!`8 \8m8n8+8E= +rint-4“)nter the siDe o.g5 ? T7%$ D'&)A/'%AA( ARRAJ" An array is used to store data in more than one row and one coloumn is called two$dimensional arrays" /ynta.gTS-”8a.alues o.alues”5= -or4iT!=i2n=iPP5 < scan-4“Sd”= Ua_i`5= sumTsumPa_i`= ? -or4iT!=i2n=iPP5 +rint-4“SOd”8a_i`5= a.am+le*$ matri.‘C’ Language int a_1N`8'8n= -loat sumT!8a.the array A”5= scan-4“SdSd”8Um8Un5= +rint-4> )nter the .

this is as -ollows /ynta.the matrices B>5= -or4iT!=i2 +=iPP5 -or4\T!=\2 E =\PP5 < scan-4>Sd>8Ub_i`_\`5= ? -or4iT!=i2 m=iPP5 -or4\T!=\2 E=\PP5 < c_i`_\`Ta_i`_\`Pb_i`_\`= ? +rint-4“The &atri.the array B”5= scan-4“SdSd”8U+8UE5= +rint-4> )nter the . sum is “5= -or4iT!=i2 m=iPP5 < -or4\T!=\2 n=\PP5 < +rint-4>Sd]t>8c_i`_\`5= ? +rint-4>]n>5= ? ? &ulti ^ Dimensional Array*$ # allows us o.‘C’ Language +rint-4“)nter the siDe o.the string8 ‘c’ uses the null character" /trings in’c’ are enclosed with in double Euotes" -31 - .am+le*$ 'nt _H`_O`_ `= /TR'AK/ *$ /trings are arrays o.three or more dimensions" The e.*$ Ty+e name array name _s1`_sF`_sH`BB_si`= 7here si is the siDe o.the ith dimension" ).alues o.act limit is determined by the com+ailer" The general -orm o.characters i"e" they are characters arranged one a-ter another in memory" To ma6e the end o.

alue is less than Dero i.the -irst string is less than the second" T! '.er the two characters in the string -32 - .another" The -unction acce+ts two strings as +arameters and stores the contents o.both are identical" 3! '.am+le*$ 1include2stdio"h3 1include2string"h3 main45 < char str1_F!`T”+hanindra”= char strF_F!`T”chowdary”= +rint-4“/tring1TSs”8str15= +rint-4“/tringFTSs”8strF5= strcat4str18strF5= +rint-4“A-ter concatenating the string is Ss ”8 str1 ”5= ? /TR #&P* $ 4string com+arision5 The -unction ctr cm+ com+ares two strings" This -unctionc is use-ul while writing +rograms -or constructing and searching string as arranged in a directory" The -unction acce+ts two strings as +arameters and returns an integer whose .string -unctions *$ ' /tr cat" '' /tr cm+" ''' /tr c+y" '@ /tr len" To use these -unctions the header -ile string"h must be include in the +rogram with the statement" /TR #AT*$ 4string concatenation5 This -unction concotinates two strings i"e" in a++ends one string and that o.the second string at the end o.the -irst" ).‘C’ Language /TR'AK 90A#T'%A/*$ There are -our ty+es o.the -irst string is greater than second" The -unction str cm+ com+ares the two strings8 character by character8 to decide the greater one" 7hen e.

am+le*$ 1include2stdio"h3 1include2string"h3 main45 < char str1_F!`T”+hanindra”= char strF_F!`T”chowdary &aganti”= +rint-4“Be-ore co+ying/tring18stringFTSs8Ss”8str18strF5= strc+y4str18strF5= +rint-4“A-ter co+ying the string is Ss ”8 str1 ”5= -33 - .‘C’ Language di--er 8 the string which has the character8 with a higher A/#'' .the second string" ).am+le*$ 1include2stdio"h3 1include2string"h3 main45 < char str1_F!`T”+hanindra”= char strF_F!`T”+hanindra chowdary”= int result= resultTstrcm+4str18strF5= i-4result3!5 +rint-4“/tring1 is greater than stringF TSs8Ss”8str18strF5= else i-4resultTT!5 +rint-4“/tring1is eEuals to stringFTSs8Ss”8str18strF5= else +rint-4/tring1 is leess than stringF TSs8Ss”8str18strF5= ? /TR #PJ*$ 4string co+y5 The str c+y -unction co+ies one string to another" The -unction acce+ts two strings as +arameters and co+ies the second string character by character in to the -irst one8 u+ to and including the null character o.alue is greater" ).

ed number o.alid range o.characters +ercent in it" ).the /tring1TSs”8len5= ? P%'AT)R/*$ &emory is organiDed as a seEuence o.bits8 labeling a byte in the memory" Addresses a-ter +ositi.‘C’ Language ? /TR ()A *$ 4/tring length5 This -unction returns the integer which denotes the length othe string +assed" The length o.e integers constant corres+onding to the last location in the memory" ).ery ob\ect i"e" loaded in memory is associated with a .address" -34 - .byte$siDed notation" These bytes are numbered beginning with a Dero" The number associated with a byte is 6nown as its address or memory location" A +ointer is an intity which contains a memory address" A +ointer is a number8 which s+eci-ies a location in memory" )ach +oint in memory is associated with a uniEue address" An address is an integer ha.e integer .the string is the number o.alues that range -rom Dero to some +ositi.ing -i.cluding the terminating the null character" 1include2stdio"h3 1include2string"h3 main45 < char str1_F!`T”+hanindra”= int len= lenTstr len4str15= +rint-4“The length o.

‘C’ Language The siDe o.Sd is Sd”8a8Ua5= +rint-4“Address o.arF= +rint-4“Address and contents o." #reating data structures such as lin6ed lists8 trees etc" .ar18.am+le*$ 7or6ing o.arTF!!= +trTU.the data ty+e is re-erenced by the +ointer is the no o.arT1!!= .a +ointer using addtresses" 1include2stdio"h3 main45 < int aTN8bT1!8cTF!= +rint-4“Address o.arF is Sd”8+tr8.ar1 is Sd”8+tr8.arF is Sd”8+tr8...ariable using +ointer" 1include2stdio"h3 main45 < int R+tr= int .bytes that may be accessed directly by using that address" 0/)/ %9 P%'AT)R/*$ i" Accessing Array elements" ii" Passing arguments through -unctions" iii" Passing arrays and strings through -unctions" i." %btaining memory -rom the system dynamic memory" ).ar15= +trTU.ar1 is Sd”8+tr8.am+le*$ 7or6ing an .ar1= +rint-4“Address and contents o.arF5= .ar1TR+trP1= +rint-4“Address and contents o.ar15= ? -35 - .Sd is Sd”8c8Uc5= ? )...Sd is Sd”8b8Ub5= +rint-4“Address o.arF= .arF5= +trT1FN= +rint-4“Address and contents o.

ariable is de$re-erenced when the unary o+erator 4R5 in this case as a +re-i.am+le*$ 1include2stdio"h3 main45 < -loat data18dataF= -loat swa+4-loat8-loat5= +rint-4“)nter any two -loating ty+e .ariable or +ointer e.ariable .+ression" ).alues”5= scan-4“S-S-”8Udata18dataF5= +rint-4“Be-ore swa+ing the numbers are S-8S-”8 data18dataF5= swa+4Udata18 UdataF5= +rint-4“A-ter swa+ing the numbers are”5= +rint-4“data1TS-8dataFPS-”8data18dataF5= ? -36 - .ar18.ariable by using the address o+erator 4U5 am+ersand" D)$R)9)R)A#'AK P%'AT)R*$ 't is an o+erator +er-orms to access and mani+ulate data contained in memory location +ointed to by a +ointer" The o+erator 4R5 is used to de$re-erencing +ointers" A +ointer .am+le*$ 1include2stdio"h3 main45 < int R+tr8.ariable .ar1 contains Sd”8R+tr5= . to the +ointer .‘C’ Language Address o+erator*$ All the .ariables de-ined in a +rogram resisted s+eci-ic address" These +ossible to obtain the address o.arF= Ri+trPTF!= +rint-4“.a +rogram .aeFTR+tr= +trTU.arF= R+trTFN= R+trPT1!= +rint-4“.arF contains Sd”8R+tr5= ? ).

the +ointer .an ARRAJ using P%'AT)R 1include2stdio"h3 main45 < int R+tr8 a _F!`8i8n8 small= +rint-4“)nter the siDe o.the data ty+e which the +ointer .the array”5= scan-4“Sd”8Un5= +rint-4“)nter the )lements o.Array" 4F5" The siDe o.the siDe o.ariable +re-ers to8 is de+endent on the data ty+e +ointed to by +ointer" 9or e.ariable i. ARRAJ*$ The elements o.bytes reEuired -rom the data ty+e +ointed to by it" 9or e.‘C’ Language -loat swa+4-loat Rd18 -loat RdF5= < -loat tem+= tem+TRd1= Rd1TRdF= RdFTtem+= ? P%'AT)R/ 7'T.am+le a +ointer .am+le i.+oints to the location 1!!F" )am+le*$ /earching the smallest element o.the array”5= -or4'T!='2 n='PP5 scan-4“Sd”8Ua_'`5= +trTa= smallTR+tr= -37 - .ariable +oints to an integer ty+e at a certain address 1!!!8then on incrementing the +ointer .ariable +oints to an integer data ty+e8 then it access two bytes in memory" 4H5" A +ointer when incremented8 always +oints to a location a-ter s6i++ing the no o.e o.an array can be e--iciently accessed by using +ointer" 415" Array elements are always stored in continuos memory location irres+ecti.

e to use the -ollowing synta.ariables in to a single antity" /truct student < int rno= int sub= -loat mar6s= /tructure name Iey word" /tructure member Declaration" ?= R0()/ 9%R D)#(ARAT'%A %9 'AD'@'D0A( &0&B)R/*$ The indi.common data ty+es such as int8 -loat8B"" )tc8 +ointers8 arrays or e.another +ointer is called +ointer to +ointer" To declare a +ointer to +ointer .‘C’ Language +trPP= -or4'T1='2 n='PP5 < i-4small3R+tr5 smallTR+tr= +trPP= ? +rint-4“/mallest element is Sd”8 small5= ? P%'AT)R T% P%'AT)R*$ )." Data ty+e RR +ointer = ).a structure may be any o.idual members o.en other -38 - .ariable we ha.ery +ointer created in the memory has an address" This address can be stored in another +ointer .* int RR6= /TR0#T0R)/ *$ A structure in ‘c’ is a hetrogenous user de-ined data" A structure may contain di--erent data ty+es" 't grou+s .ariable " the +ointer which stores the address o.

ariables o.ariables o.the ty+e indicated by the structure tag" /TR0#T0R) 'A'T'A('/AT'%A*$ /truct student < char name4FN5= int rno= int sub= -loat mar6s= ?= A .ariable o.ariable can be s+eci-ied a-ter the closing braces" struct student < int rno= int sub= -loat mar6s= ? student 18 student F= /tudent is the structure tag" /tructure 1 and structure F are .the structure are not reEuired the tag name student can be omitted" 4F5" 0/'AK T.the structure may also be declared se+arately by using the structure tag" /truct student student 18 student F= student 1 and student F are structure .) /TR0#T0R) D)#(ARAT'%A*$ The structure .ty+e student" '.other .ariables o.) /TR0#T0R) TAK*$ The .ariables o.‘C’ Language structures" All member names with in a +articular structures must be di--erent" 'ndi.this structure can initialiDed during its declaration as shown below" /truct student student 1T<“AAA”=HF!N8F89!"N?= -39 - .idual members cannot be initialiDed inside the structure declaration" D)#(AR'AK /TR0#T0R) @AR'AB()*$ 415" 'A T.

ariable o. 'A /TR0#T0R)*$ struct date < int day= int month= int year= ?= struct +erson < char name_FN`= struct date birthday= -loat salary= ?= The embaded structure ty+e 4date5 must be declared be-ore its use with in the containing structure" This is because8 only legal data ty+es are allowed in the structure declaration" %P)RAT'%A/ %A /TR0#T0R)*$ ‘#’ +ro.ar” is on is one oits member" The dot o+erator must ha.a structure inde+endently" The dot o+erator connects the member with the structure .ariable and “member .‘C’ Language /TR0#T0R) 7'T.ar= .ariable on its le-t and a legal member name on its right" /truct +erson < char name _FN`= int age= -loat salary= ? em+rec= em+rec is a structure .ar" member .ides the +eriod or dot4"5 o+erator to access the members o.ar” is a structure .er “struct .the structure" )m+rec" Aame will access em+rec’s name" )m+rec" Age will access em+rec’s age" ARRAJ %9 /TR0#T0R)*$ -40 - .ariable" This can be re+resented as struct .e a structure .ty+e +erson and name8 age8 salary are the members o.

ere student struct is the tag" /tudent is the name o.ariable" in the -unction call statement we s+eci-y the structure .Nth structure" TJP) D)9 /TAT)&)AT*$ Ty+e de.ariable as an argument" 7hen we +ass a structure .ing structures" A new data ty+e re+resenting the structure is declared using the ty+e de.1! +erson structures" )ach element o.ariable will be +assed to the -unction" The structure .ariable" /truct +erson < char name_FN`= struct date= < int day8 month8 year= ? birthday = -loat salary = ? em+rec_1!`= em+rec is an array o.the structure .struct student struct < int roll no = int sub\ect = int mar6s = ? student = .ol.idual members" An array name8 salary and another structure data" “em+rec_O`"name” access the name o.ariable can be +assed to a -unction in the same manner as that o.ty+e +erson" The +erson structure consists o.6ey word" Ty+e de.‘C’ Language The array will ha.ariable to a -unction the entire contents o.an ordinary .the array em+rec will contain the structure o.e indi.ariables" /TR0#T0R) %9 90A#T'%A/ *$ A structure .idual structures as its elements" /imilar to declaring structure .statement is used -or de-ining new data ty+es in.ariable declare in the -ormal -41 - .the new ty+e" /tudent student 18 student F= /tudent 18 student F are structure .three indi.

5= .the union use the same s+ace indi.er lay o.ariable or an e.ariable3`= All .idual .ided by the com+ailer" 'n case o.ered by a .ariable name3= BBB"" BBB"" ?_2 union .+ression" The synta.memory reEuiring is the same as that reEuired by its largest member" /'C) %9 4 5 %P)RAT%R*$ 't is also called com+ailer o+erator or com+ile ty+e o+erator" 't dis+lays no o.erwrite the other" )lements o.ariables in a union occu+y the same location in the memory" Thus writing into one will o.ariable is the sum o.ariable" 7hen e.the 6ey word “0A'%A” -or the 6ey word “/TR0#T”" 0nion _2union ty+e name3` < 2 ty+e 3 2.ailable to all the -unctions in the +rogram" 0A'%A/*$ A union is a ty+e in ‘c’ which allows the o.the actual .siDe o.bytes co.ariable in the same memory area" 0nion is similar to a structure" The only change in the declaration is the substitution o.er we +ass .siDes o.integer ty+e" -42 - .all the members in addition to the +adding bytes that may be +ro.a union or accessed in the same manner as the elements o.ere n should be o.ariables inside a union share storage s+ace" The com+ailer will allocate su--icient storage -or the union .ariable to a -unction the structure must be declared global8 this is because the structure de-inition must be a. o.more than one .o+erator is nTsiDe o.ariable to accomidate the largest element in the union" %ther elements o.‘C’ Language +arameter must belong to the same structure as that o.a structure" D'99)R)A#) B)T7))A /TR0#T0R) AAD 0A'%A*$ The amount o.a union8 the amount o.memory reEuired to store a structure .4.

is .9'()/" %nce we store the data +ermanently that data can be used -rom the -iles when e.ice .ariable" e is an e.alue and +rocess to con.‘C’ Language .ersa" /o it is also used -or casting a . is .ert o+erator" This o+erator con. is as shown below" This -unction o+ens the s+eci-ied -ile and returns a +ointer i.alue" /ynta.ice we ha.ariable" TJP) %P)RAT%R*$ Ty+e o+erator is used -or con.the -ile has been success-ully o+ened" %therwise it returns a null .e to -ollow the -ollowing ste+s" i" select a sutiable data structure -or the -ile " ii" select a sutiable -or the -ile and o+en it" iii" Per-orm the o+eration on the -ile" i.e to use the conce+t o." #lose the -ile" %P)A'AK A 9'() *$ To o+en a -ile we ha.e the -unction -o+en4 5= whose synta.ty+e o+erator is 4ty+e 5.* 9ile R +ointer= ).erts -loat ty+e data in integer -rom and .data items or in-ormation stored some way on the secondary storage de.ersion +ur+ose" /o it is called as con.er necessary" To do -ile o+erations we must declare a +ointer o.* 9ile +ointerT -o+en 4“-ile name”8”mode”5= -43 - .ty+e 9'()" This is because a -ile can be accessed only through its +ointer" /ynta.+ression" 9'()/*$ A -ile is a grou+ o. o.ice" To store the data gi.* 9ile R -+= The o+erations that can be +er-orm on a -ile or reading and writing" To +er-orm any o+erations on a -ile we ha.ere .en to a +articular +rogram on a secondary storage de.erts -loat ty+e data in integer -rom con.ert one -rom to another is called casting" she synta. or e 7here .

ists a new -ile will be created" 7P*$ 'dentical to w" but allows both reading and writing o+erUations" RP *$ %+ens a -ile -or reading and writing" AP *$ %+ens a -ile in a++end mode and allows reading also" R)AD'AK 9R%& A 9'() *$ To read .‘C’ Language 'n the abo.alues -rom a -ile" 7e ha. -ile +ointer s+eci-ies the -ile where the contents or to be written" #ontrol string and .ariable list5= in the abo.ists the contents in the 9'() will be deleted and the new contents will be return to the 9'()" '.the -ile e.ariable list are same as that in +rint-4 5= ). -ile name is the name o.* +rint-4-+8”nSd]nSd]nSs”8 em+"id8em+"sal8em+"name5= -44 - .the 9'() doesn’t e.4-ile +ointer8”control string”8U .ariable list5= 'n the abo.* -scan-4-ile +ointer8”control string”8U .the -ile which is to be o+ened" &ode is the +ur+ose -or which we want to o+en the -ile" The di--erent -ile o+ening modes are 78 r8 a8 wP8 rP8 aP" 7 *$ %+ens a -ile -or writing only" '.that -ile" 7hen a -ile is o+ened in this mode the e.e synta. -ile +ointer s+eci-ies the 9'() -rom which data is to be read" #ontrol string and .isting data will remain the same and the new data will be added -rom the end" '.e synta.e the -unction -+rint.4 5= /JATA: *$ 9+rint.the 9'() doesn’t e.e synta.scan-4 5=" /ynta.ist a new 9'() will be created" R *$ %+ens a -ile only -or reading +ur+ose" A *$ %+ens a -ile in a++end mode" This means that we can add contents to a -ile -rom the end o.ariable list are same as in scan-4 5= e.* -scan-4-+8 “SdSsSd”8Uem+"id8em+"name8Uem+"sal5= 7R'T'AK A 9'()* $ To write a -ile 8we ha.e the -unction .

the 9'() +ointer in the 9'()8 i"e" no o.e in the bac6 ward direction" 9tell4 5= *$ This -unction returns the current +osition o.e .alue it will mo.4-ile +ointer5= 9ile +ointer s+eci-ies the -ile -or which we want to detect" RAAD%& A##)// %9 9'()*$ This means locating the -ile +ointer at a desired +osition in the -ile" To achie.4 5" This -unction returns n true .* 9close4-ile +ointer5= ).the -ile otherwise it will return a -alse .the -ile we ha.e in the -orward direction" '.we s+eci-y the negati.we s+eci-y a +ositi.e" This +arameter s+eci-ies the no o.‘C’ Language #(%/'AK A 9'()*$ To close a -ile we ha.the 9'()" /ynta.* 9eo.e the -eo.e the -ile +ointer" '.alue -ile +ointer will be mo.e the -see64 5= /JATA:* 9see6 4-+8 no8 o-by8 +osition5= 9'() P%'AT)R*$ This +arameter s+eci-ies the -ile +ointer which we want to mo.it has reached the end o.e this tas6 we ha.alue" /ynta.bytes by which we want to mo.e .bytes it is away -rom the starting +oint o.alues i.* 9close 4-+5= D)T)#T'AK )AD %9 9'()*$ To detect the end o.*$ @arT-tell 4-ile +ointer5= -45 - .e a -unction called -close4 5= this -unction ta6es one argument which is a -ile +ointer" This -unction close the -ile which is associated with the s+eci-ied -ile +ointer" /ynta.

*$ :T-tell 4-+5= )A0&)RAT)D DATA TJP)*$ )numerated data ty+e is the data ty+e de-ined by the user it allows the user to de-ine this own data ty+e" To declare the enumerated the enumerated data ty+e we use the 6ey word enum" /ynta.e synta.*$ )num name <constant?= ).alue the .*$ )num colour <red8 green8 blue? -46 - . 9'() +ointer is the +ointer whose current +osition is to be 6nown" /ince this -unction returns a long int ty+e o.‘C’ Language 'n the abo.ariable should belong to long int data ty+e" )..