Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
29 views
C Language Notes-2
Uploaded by
Varshitha Reddy Matta
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C language notes-2 For Later
Download
Save
Save C language notes-2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
29 views
C Language Notes-2
Uploaded by
Varshitha Reddy Matta
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C language notes-2 For Later
Carousel Previous
Carousel Next
Save
Save C language notes-2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 40
Search
Fullscreen
fat as Gormat Spectfier ¢ “Frofeam tnt { p= tps p> variable name Ink tps i q Ee vets of var a ra 2000 8000 —s address of vor P= a5 : ee eat ; tnt a= toe one Clk oe S 000” $000 f / Te ti TU Nudsighed fete oe (ave values. oly ) main () | inta=to, tp, p=Sas | print® Cased" ads [lacie prntt (“as ‘bat "pds Mazi ig print® ("a eeu" Lays Na- 2000 prot (“asehu" py iy ot 2000 return 06 ; address of variable value ot that addressAdvantages + we can directly access the data . 4+ dynamic memory altocation and deallecat on > resize the memory . Disadvartaqe 7 FP value ts net asstgned to pointer, segmentation fault, Tt will show m wWiicle © Pregram=te odd tise au bbe, using ‘potsters APincludecstdfoshS tht maine) { tnt a=lo b= 20; Tete a: paka?y qe kbs printt (“sum = 7d" pata) return Oo;. cinters. ¥ write a C program to swap two numbers using P: abinclude
| Trt main ¢) : , { Tint a=to, b=20,*p tq « pr tas qe sos “pe “pata s “y= *p fq s “Pi Sp nto print€ (Nase/ed\n bethd” €p qs return 0% Nop PoinTeR Tt can hold auy datatype &i tntas a Rloat bs i) void *P Fy 3 p=%a lor) pe tb 3 q= 2a tor) yetbs“ write'e C program to print ftoat and character type using pointers : Htinclude < stdrosh> tnt main () { Float b= 20.6 : char ch = ‘a’, vofd tp tq 5 2 paxbs gq = &ch 5 printf (“be 8 \n che foo”, tp, tg); return Os ; \ ‘01 09-22 . 2 ContRou Statements rogram based on condit onal \ > Flow of execution of a P and uncond?Honal statements, : A a woe my > one part of prograri'“lo another ‘part Sf program ContRoL a Stitements > ao Onconditional statements break goto Oectercn / ae control loop / a * . atu . telection stad errenls Heralian Statemens Statementeersions statements © © Simpre ze > me-wiay selection Statement’ Syritox + Statement—x s & Ceondition) ' Statements + : Statementiy ¢ Flow chart +pragram + Abinclude < stdio-h > : int main) { tnt x = tos re Cx > 0) { x4 printf ("x value is ha " mays) préntf ("this main prodrar”) 2.5, return 0; : rym doing meg i 4 «CC tesy w He Shag gif-else STATEMENT : > two-way seleckon statement 3 SES an extension for ciple 2 Syrtax : Statement -x $ d f2 Ccondition) I] state ments + y else { Y |] Statements :* Write a C program do check whether the given year 2 leap year or nots ttnclude ¢ stdiorh S int smain () { int year » erint® (* eater year\n") 2 feet” Fed", Kyear) 3 € ( year 7s ye od) , printf [: Leap year”) : else print C" Nota leap year Ne return 0; j () else-fe Lapper Syntax ¢ Re ech 1) i Statements 3 3 else 7# Cton-2) t Statemente ; y - else Statements : 3ce (oor S Nite a Co pregram to print the colours of VEBBYOR, include
int main 4 char ch ¢ erinté (“-thter aces \n")s Seanf (“%e", $eh) TE (che = Sv’ [| che =sy') print€ (“Wiolet") ¢ else i£- (che || ch==“i!) print€ (“Traigo") ¢ else tf (ch= = ‘6! || ch ==‘b') printé (“Btue") » else 8 (ch== ‘6! [] ch=='9/) printf (“ Green") 7Neéstep f-else Syntox : else 72 (ch==‘Y' Il ch= ety’) print Cyettow") ¢ ie else t@ (ch oir ch= : a : 2 prenté. (" Orange") a else 2 (chet 'R! [che a'r) + print C’Red") we , i e else : : a print? (“Tvabid") > T \tew tall return 0; eee. & $0 (condition 1) if t2 Ceondition 2) { Statements 2 oA i 5 : - else f Stotemenis's r# write a C program to check ehether: the aver pomber: pettus or negetive number, tfneludle < stdfo-h> fat main ¢) int m ; We Scant ("%/-d" an) 5 € Cn>=0) TE Cn>o) print€ ("positive no.) else ) print C2ero") ; ‘ else oe a printf (“negetive no." )3 3 return Oy® ulrite a C program to “find the greatest of ee nombers . AW iheluce
kt) - ; : : else. { shy U Cbocy print®-( “vd ts greatest”, b) ; else : printé (“vd ts greatest | els 3 return o;SwitTCH vault? wey election Atatement Syntax Sustteh (exp) { case Cabek_t2 g M Statements break 5 case Cabel_2 If Statements + break ¢ ease bab ¢- de@ault + [| stotements ms break ¢loop STATEMENTS loop —s set of PnPdwections (or) stolements evecuted repeadily unttl the condttion be-fole, tom Ww wed. > kntry~ controlled loop ( pre- checking loop 4) Ly vote, for > Gil~ controlled (oop ( pot teat / pod = checking loop } Ly do-schite uthile Loop Syntox + fnttialfratfon : while Coondition ) I body of Statement : therement / decrement s louchart + tri tal fealion Statumenly incre [deere enprogram Winclucts <6tdéoh S ofp: A - e fmt main) : 4 c S int Pats while (P< 10) f 2 7 : print? (“%/ed\n”, &) 9 C++ s to i return o 5 DIFFERENCE ByyO WHI AND foR white. for te alt three fn « We write fitialiadtion, > we ae = conditfon aust frere/deere, one. step - in three diff. steps. foe ; for ( vuthialiaatisn ¢ eoudilion ; ducrewut /dscreusen Syvitox + orc ue oe A act of darlrudious .propia Nthelue €etdto dhs ul matin { : fot ? 5 for (tats few erty { print (edn Ys } Co " wn Oe relorn 07 % Write aC program “lo (ind aum of fodtutduod, digtts of nomber. .: Aktnclude ¢ atdiorh> tnt main O { tae inl nr, sums Of print ("-Cnter ns") ¢ Sean (“Ad : %n) : uthile (n> 0) f 1 als Re nZlo ¢ Sum= Sumi h=n/io; printf (“som 1 /-d", sum) return 0;g write a C program to check whether the given number 16 palindrome or not: avinelude ¢ etdiorh> frit math O t tnt nm, ©, sum-o0 ying. preate Center ne 2 4 Seang Ly d" an) 2 tne ao whfle Ens. 0) { A re n%lo¢ Som= sumtiot r 2 n=n/io; cy 3 Sana parte (tn = = som) oo print C“ poltndrome") else printé c" i “halindreme! yy vetérn Oy ide in baa)¥ bite a 0 program “to check whether the given number Ys armstrong number or not Abinclucte < stdforh> tnt matn () i tnt n, +, dum=0,4n 2 print (“Onter for bey 7 Seon€ ("Yed" $n) ae Ane=ns whl. (n>o) “on re n%lor nm Bom = somt (r¥r &r) » N= n/lo ¢ 3 C2 Ctn== 0m) prenté (" armstrong no: ie else prime (“not armstrong vio") = + return © 3* ulrite a C program lo print -the table of given number. ak include < stdoh> tht main () f ° unt Lc Print ("enter number ") s Sean€ ("Ag "ands for (a1 otce { loz tt+4) wen*?, print (Md ™ Yd = pdm, or): 5 rek 3 urn Ooaol fon Mette 6 CO progeaue to prank (otlownng! Polen * £ eg et ” * % 4% ye vey, ALincluds¢ stdiosh > fat moin ¢) f ° tnt v7 Vd ' _ for(fateitzetod tir) { print C“eted +"); printf Xn"); 3 return O¢Al ticluds ¢ eteliohs val usiain cy t wtp. ' for (bet Pent 3 by) { i hor (jets feng gas) f ; printe (dt) 2 priate ("\n") + 3 return O;, a t 2 (23 2s 4 teas 4 & Atindlude ¢ stdiv:h > tht matn¢) { tnt OF for (fats Cc=t0; ett) f for (jet a Jeet s fet) f printe (°%-d" js ernte (Sang } . ; 5 relirn oO; i w. « ek & Kee Ke & eee Ee KE we eK Kk kw kK &gptnclude < stded-h >, ed maine) ' int rows, &, JK <0 : print€ ("tnter novot rows: ")s z dcan€ ('x%d" Srows): lor ( Fats fe =rows » £444,120) { for fats jenrows ; far) | pract? (" yi 5 while (k I= (2*F-1)) { pratt CR") s Keres ++ky 0 (7, ' ~{ > hivan aa? "9 m ie=ey printE COXn") 5:4 J return 07yr —————_—_ | __ ‘ numbe ane given r mw write a Cc program ‘to check whedher M4 & perlect number or not: Winclude
=t { 7 Tf oct» Lact? s Scant (#7 4 t--¢ do _ f Z \ prénté Ud" Lact) + vetunu oO; Pe 4 oo os C++ 2 7 } white (fZ=n)UNCONDITIONAL Stateme NTS > break. : : j | ~ continue wed w loop So atateusits | . return cud execchon a values, variables, expresstons Bdom 4 tnt main 5 t tt num, ¢t 2 ao print€ (" enter number”) 2 Scan ("/-d", num) ¢ for (fats Cari0 7 C44) ; | t : Yo: 3 7 t€ (ebm =<) : : break + 3 print eCteeg”, nom) relorn 0; 4 2 oS 4 o 7 & q aot (num - 2) Of: % coutinus 4 putt ("2a" wun)s retoru 0% Stk: sorléets te=moms fr) Se { fF (mow = =5) goto Att » —ferayS ——° > store collection of data'or elements: with Aame.+ dotatype- > Store homogenous eillettion of data : Syntax: dual 7 datatype arrname[ atze] :tht als); , to | 20] 80 | 4o] 50 fF Memory becuphed : 5x2 ato} att) ale} ats] alu) sto bytes. ADVANTAGES ° 0 Stores homogenous collection o€ data 2 Code optimteation Ls tess codento access the data. 3) Memory ts allocated continuously . DISADVANTAGES ——o Bese 0 Array Atze u €iked 2 Memory iy wasted, 3) jn Cnsertean ied deletisn no o€ elements "es dr@edicutt Arrays ‘ : i t Dimenstonal.. > 9- Dimensional * Multidimensional. oe ae10 Array datatype Sree rere : tnt a= fig) : tnt a fs] = {t0,20,30, 4o, 50} 3 int als) = fo} : tnt alS] = fto, 20,30} — automaticalty takes other variables as Zero. int al] ={ te,20, 86,40,50, 604 °, 2D Array) iT 4, dotatype arrname [sooaize][colomnsize) » o Multi - Dfmemtonal Array fieatiags datatype arrname [sized] [sitter] _-.[steen] 5 Tiitfalledon- [Ce int afs'] = 10,20, 30, 40, 504 ofS) = [te,20,30f — other Aeuoim O- char name [20] ; « char nau [10] = Kavi” » ? char mame( J =" Wekouts ©” o 2 char name(s} = TR Al yl Gey* Writ a ¢ program # dead tre foot a elements aad Print: ‘of loctt array elameuts . tat matn() t loot tts) ; print ("Snter array) chant for (084 the sty Seont ("7.e%, sareq), for (i=0 ; fee, fe) printé ("Ze ay ‘return Os “4 & ulrfte a C program to print personal details pea student [Information t'ke student name, student'rell ae) Student marks a] 6 subjects, total, average J— arinelude
9 33 | at ent main 0) { char ch[201 ¢ a F tnt roll ¢ tfoae £=05 S tnt marks [6] + ust CF ; / . float avg 4 sp nes eu eee prnt€ ‘(Center student name, roll noe 7 ')'54 seane (“%S%/-d", ¥ch / AOblezroll) » printf (“enter marks +") ¢ : for (feo, feeb: TH+), a scanf (Sa/ad", Kot marks [é] ) 2 for be on; bate 5 THI t= t4marks(i] 5 ovg = t/6 5 printe (es\n %dX\n')¢ for( f=0 + fee. y fat) print€ ("7-4") marks C7)) s print€ (Xn total! Ad \n average: HO % t,0vg)2 retorn 0si t te program to read cGPA 4 to Atudev dud Print them. AP tucluds < etdioh > Gal main 0 f float egpal to] 2 tat €; Priel (Order egpa af 10 xtudinls 7 Seon . for fo 5 Pe 10 7 t44) sean€ ("7-6") ogra de, i for (f=0'; ¢kr0; U44) |. print ("*¢Sne, egpa él) + relurn OsU5 phe p 202% tor strug, Ahere u mo need ed: we tw ean: statement . ex: scant ("*/-s") mawe) + TSeco2, the string B imteral’ poste mr. Ot dire ely pownters the characters. CEoncTions we write'a: complex prigrau : 7 His Mucuit for readability, te & also diffucult for ceusabititi/ 2 jAts's debaggiig " iy 4) 0 oe A block o€ code which performs specific Hosie wher fe & Cmvokted Cor) called . Functions are alse called moclule design cor subprograr Cor) user-defined functions2 Aovantages oF functions __ o D Readabrttty 2 Reaumabiltty of code 3) Bebuaging]t eary/ 4) | dtvideag large program into mo-of modules lor) Lunetfons , “types of functions __o . ° WW Butlt—f function (or) Standard. Ubrar Lunétion = in unero! y @ these Lunetvons are already digined and storeal th the Comelter a i Any modi€fcation done by user will not reflect Deter We donkh know tnternal wor king of bul ti tn £unction , ©) User-defined function Created by wher. Any modification canbe done by user , User can kow fnternal working of function , cetl() —> round off the Floating Valus.; : ganelrons has three acpects < ucer- ded ine! une. eallid by a Punetton declaratvon | rmaint) dune: 2) Catting a fonction eee : [otuay (3) Function de€%ton, operating Basten. Syntax, a . : dey returntype funename ( parameter (at) 2 J wo. clatot yp e arguments \ ( tt, float, char, Als valuet (or) verd ) oe * Varfables (or) data. pos ed throug b function . etevalios cs —fanitidn dat (Aum ( tht, Pint) Before maini), we have to declare the function , 4 ‘ fs .Tanetion de€inttion ° function header’ * selurntype tunename ( datatype varts datalype var2) + { Syntax i logite : nition b I body of function; % “anener dy ase sthiuclude < stdio+h > det aul tnt, aE) = Y) Lundlion declebalion int main () { fnt a,b,c ¢ Scant (“Zdef.d') ga, 9b) + peduel ——s pore" ula re = sum(a,b) 2 Puff callin 9 function print (“ex ted" e) 5 endef J formal Prey : ROE cat eve : a um ( ee uty) lv burel fey, dienihen return keys > relurn to call, 1g durtiouCLASSIFICATION oe SOLUNG, A Punetionl . i (WIth parameters 9 with vetorn value ) with parameters e owithout retorn value (3) without Parameters ®» with relorn value, CH) without parameters # without retuen value. mM Sep 22 ’ aw prograu £ Au of boo fai . “ot sum ( tnt @, tnt b) fit main () : eV do { tht a,b 363 Scanf (“%dlefed", ka, xb) 3 C= Aum (a,b) ¢ . ! printf (Saeult © fd" ¢) 2 retorn 05 : fat Aum ( int, tnt &) cetureath< tnt oe g CHKtY Ty » returnc -om B) votd au (rut dat) fut ain O { Pat a,b + Sean (“*a¥/.g", 80,96) 5 dow (a,b) 5 reluos ] void sum Cint x, ent y) £ a Tut ce c= kty 5! printe (8.4 e)s ° 10 Gab a Pbi"e + CHath . 3 Print€ (* dui’ = “/.d", fc) >uw ° wt sun ( ds void main ¢) ° tnt Aesult : result = ~zum( ) 3 Pinte ("result © yd" seule) ‘ Botd “autin (. iy ita be 3 C=ath. 3 result return es J) Passing Pavameters Techniques 8 +3 colt by value (data. ) 4 calt by seference (#) = | & void swap ( tnt, int) s tnt main 0) { Vea A PRP VY int ay, b> z 2 ae i pointe Ge enter a,b values hk ae ‘sean€ (* a ed * ", da, 3b) 5 4 brinte cC Sefore Awapptag : a= td, b=d" af): * swap (a, by; retorn—O; print? ("Aéter Swapping saz yb=/d", a,b):vord swap ( int x, int y) t tnt ts t=xe ae : t Coe Print C"ARter sunpping 1 MeM/-d,ty= "had x Y)s Call by value > copy value to the cated funct or, > any changes made tn the called functions will Mot e€fect tar cating Runelion .” Can by ference void swap ( ft » pint x) ft mart f t tnt a,b : printf ("
( Sa, %b) 5 : ' ‘pri? (* Aeter Swapping Lastd, be7.d" a,b), retomn oy usvoid swap ( eat *x int *y) ¢ tt t 9 ta 6 ay ih 5 Hy
You might also like
PPT
PDF
No ratings yet
PPT
31 pages
C-Lab-manual
PDF
No ratings yet
C-Lab-manual
16 pages
C Language Notes-1
PDF
No ratings yet
C Language Notes-1
41 pages
C Programming Lab
PDF
No ratings yet
C Programming Lab
39 pages
PPS LAB MANUAL II SEM
PDF
No ratings yet
PPS LAB MANUAL II SEM
46 pages
BSc Final_C-Record
PDF
No ratings yet
BSc Final_C-Record
34 pages
MAT & C Lab
PDF
No ratings yet
MAT & C Lab
32 pages
PC Lab Manual
PDF
No ratings yet
PC Lab Manual
23 pages
C Lab Manual
PDF
No ratings yet
C Lab Manual
25 pages
Stand-Alone Programs: Alpha, Beta, Gamma
PDF
No ratings yet
Stand-Alone Programs: Alpha, Beta, Gamma
16 pages
c Manual
PDF
No ratings yet
c Manual
31 pages
C Lab Manual
PDF
No ratings yet
C Lab Manual
16 pages
SEP BCA - C LAB MANUAL
PDF
No ratings yet
SEP BCA - C LAB MANUAL
22 pages
Programming Through 'C' Language
PDF
No ratings yet
Programming Through 'C' Language
91 pages
C Program Rcu
PDF
100% (1)
C Program Rcu
52 pages
C Full Programs
PDF
100% (1)
C Full Programs
26 pages
C-Full Programs 001
PDF
No ratings yet
C-Full Programs 001
25 pages
PST Programs
PDF
No ratings yet
PST Programs
14 pages
SVVT File
PDF
No ratings yet
SVVT File
34 pages
C Programming Notes Part 2
PDF
No ratings yet
C Programming Notes Part 2
24 pages
C Lab Manual
PDF
No ratings yet
C Lab Manual
42 pages
2021 Solution
PDF
No ratings yet
2021 Solution
26 pages
Assignment 2
PDF
No ratings yet
Assignment 2
21 pages
C Language
PDF
No ratings yet
C Language
26 pages
I Sem Lab Manul C Programming 23-24
PDF
No ratings yet
I Sem Lab Manul C Programming 23-24
41 pages
RECORD.pdf
PDF
No ratings yet
RECORD.pdf
74 pages
2 CP
PDF
No ratings yet
2 CP
10 pages
Final Record Programming in C Lab-converted
PDF
No ratings yet
Final Record Programming in C Lab-converted
160 pages
C Language
PDF
No ratings yet
C Language
25 pages
Be - First Year Engineering - Semester 2 - 2023 - December - C Programming Rev 2019c Scheme
PDF
No ratings yet
Be - First Year Engineering - Semester 2 - 2023 - December - C Programming Rev 2019c Scheme
19 pages
Cs3362 C Programming and Data Structures Lab Ece
PDF
No ratings yet
Cs3362 C Programming and Data Structures Lab Ece
105 pages
DA1 Solution
PDF
No ratings yet
DA1 Solution
32 pages
Computer Programming Report
PDF
No ratings yet
Computer Programming Report
14 pages
Final C Manual
PDF
100% (1)
Final C Manual
186 pages
C - Record
PDF
No ratings yet
C - Record
38 pages
Set 1: Simple C' Programs
PDF
No ratings yet
Set 1: Simple C' Programs
126 pages
Set 1: Simple C' Programs
PDF
No ratings yet
Set 1: Simple C' Programs
126 pages
CS Programming in C Record
PDF
No ratings yet
CS Programming in C Record
39 pages
C Program lab Manual
PDF
No ratings yet
C Program lab Manual
24 pages
CP lab manual
PDF
No ratings yet
CP lab manual
20 pages
CPPM_Journal[1]
PDF
No ratings yet
CPPM_Journal[1]
15 pages
C Programes
PDF
No ratings yet
C Programes
49 pages
PPL Lab Assignment Code
PDF
No ratings yet
PPL Lab Assignment Code
30 pages
C-Language Cheat Sheet
PDF
No ratings yet
C-Language Cheat Sheet
5 pages
Bx4002 - PSP Program
PDF
No ratings yet
Bx4002 - PSP Program
29 pages
C Programming Lab Manual
PDF
No ratings yet
C Programming Lab Manual
27 pages
Fods in C Lab Manual
PDF
No ratings yet
Fods in C Lab Manual
93 pages
DocScanner Dec 14, 2023 12-01 PM
PDF
No ratings yet
DocScanner Dec 14, 2023 12-01 PM
20 pages
C file
PDF
No ratings yet
C file
31 pages
Why Doesn't C Support Function Overloading?
PDF
No ratings yet
Why Doesn't C Support Function Overloading?
17 pages
C Progms List
PDF
No ratings yet
C Progms List
32 pages
Write A Program To Print Diamond Inscribed Inside Rectangle: Solution
PDF
No ratings yet
Write A Program To Print Diamond Inscribed Inside Rectangle: Solution
28 pages
DocScan 11 08 2022
PDF
No ratings yet
DocScan 11 08 2022
17 pages
C Lab Report
PDF
100% (2)
C Lab Report
45 pages
c-to-python-programs
PDF
No ratings yet
c-to-python-programs
4 pages
C Programming
PDF
No ratings yet
C Programming
42 pages
C Language Lab Manual
PDF
No ratings yet
C Language Lab Manual
35 pages
Programming in C Lab Manual FOR Diploma in Ece/Eee
PDF
No ratings yet
Programming in C Lab Manual FOR Diploma in Ece/Eee
18 pages
foc unit-5
PDF
No ratings yet
foc unit-5
12 pages