0% found this document useful (0 votes)
31 views20 pages

Important C Notes

The document discusses various programming concepts including search algorithms, sorting algorithms, data structures, and file handling in C. It covers linear search, binary search, bubble sort, and the use of structures and unions for data organization. Additionally, it touches on time complexity and the importance of understanding these concepts for efficient programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views20 pages

Important C Notes

The document discusses various programming concepts including search algorithms, sorting algorithms, data structures, and file handling in C. It covers linear search, binary search, bubble sort, and the use of structures and unions for data organization. Additionally, it touches on time complexity and the importance of understanding these concepts for efficient programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

int)oof set, Pohon.

wiT
lon

conditton at
O whut i bNNt9bN
Bttea OPeraion aBo nown
’ Tne condition aldecisi on wnanintool that
OPeratoyr iso a
ternaY
textcondino ino Pronaming
wer ed to looP5.
whie, it or foY?
stutements line
costeing 5 TYPe casin in c lanoua Ses
TYPe Gaps
is wsed toconverta
on data
anothen.
+Per to
Arithmntic. EnmesZion ?
. what is an
en Pre3ion i a combinaion ot
An AitnVmatica,la

OPenant and oPenatDY

Precedence and A830 Ciaivittof oRehato


oPeratur aPPear in an euPneszion.
when mipAe
Pne ce dence Aetermine whibns OPenator is, eva luated
have he Same Pnece dence,
Ant. hwo oPerator
determínes
onder of evanaio
aRS0 ciivit
ssociatvitt Ruhe oiN wo
A
ator8itesj
Left to Right- oPer Same Pnece dence ane
evalaed om Left to Right
RiBht to Lefti-lsomeiroPerotrgi( i v e ' ro
assi9nment) ane evadnuted bm to Ll.
1. Se.an ching.
) Linean Sea Gh

checu eaeh element one by one

"Best Cose Fomd at hnst Place

Wonat case- Fowd at bst Placeo


Time Complenit: o(n)
Advantule: utoroTo
VenySimple to under stund and imPle ment.
NoNeed Ar the dat to be 30nted
work

Di advontue
Tne hoeut n on9e data s e t 3 9
Toves O(n) Hwe even t the elementis ean te
end.

Binary Search Biamy Seer ch i a Searoh agonith


or Anding the Posihon of an eleent ina sb
'Sorted ara
&otsofo
Best Case. o() (if the middle element is the target
Avara 9e caseOln)A bNO 9305b337
cusse
'o)urfascs9eo
bois f1o, 209w 3e 40 50, G070
NotonlowsTarget 40
1. Low =O, hih6
-btivto;9 o4h
id - (0t6) /23oto igpia of
3.

uingo larg etundatjnde n


Search(n9 A 9onithm::NETne Ser ching a6ritm

are s

to Sear ch or
e d n

ind Onel ormonethan


Ove elemevt o a a data 3etN0 obed
elenent in increasin9or
Sor in9:- Arrau 3in9
decne asin 9 order.tels
a) Bubble Sort In Sertion sort Selechon Sont

4 0rden af Gomplenity

compleitt=tow tust (or slow)


or den of
Snow with inPut 812e.

Alo go rithm. Gode GosleeITime comPlenit.


Linear Seerch Ghech ench element8ac oln)
Divide array into
Binart Search
halt ench ime.
Bubble Sort, Selecho
Sort, nsention sont Two nested loop

6. wh at i8 ThoboBe case

Bose cse:- heconiion under Whieh the recurio

Stofig - x ArsW N2x:NV N/6lo


Re cur8ive ce:- The Part whene the' ucioy cal&
Problém down.
break the
itzelt to
&. Filbonacei Senies.
Se4uence whenc each term
’Tae Hoonacci Senie8 Previos ter
i8 the Sum of the
21,34...
R t ew Filonacei nMm bens! 0 , 2,35,8,s,

Forwwba Fw)= f(n)+F (a-)ss


Buse Cosez'. F()=0, F() =|eg
data WPe that alow8 rouPin 9 vaniable of diffenc
HPes nder one hameo

whY wse structyne

)To Sroup lp8ica Related data Cieasy


bay.
i) HelP in ordani3in9 datu in a meaning tul
H) Retten thun annays when daPoa tYPes ane aareut.

Sheuet student wot 5 e l o


int nodl'
.5Chahame 50
leat manka NSAS N3NO

int mainc)l
Stnuct srtudent S1;N b
\):
Pritf Enter rol, hame, end marK8:

Print! student
Ale Peiutt Rali 7.d\n Name: 7. n manws: -2fn

Asta?
3
OutPut

lol

Shud eut betalls -(-w)1


Roll? Lol.
abed
behnin 9 stnuetunes;
2 to beine Shouotue
StePs

etruct veywond
inside the logy.
membens (vamialkle) variable
2. behne
StrnctuYe to declone
the
3. yse

Char hame [ 50];


lpat marns,
declear variable
You Can

-NSNENN to Inside
st delemt
outside the stouctune 2.

Shruct Student
Struct shudent S1;
int id;
char name [So]
out nsi

Array of Shouctures
stohctune to store
omnat of
we ca cneat an
wlhple ecodB

I a inear dita
Notion af Linyed List- A uMed l t
Pointer to tae
Sructuve whene ench aemont (node)
hent

TYPe of Lined List


node Point& to the hent
List - Each
Sin 943 Linved
node ot. Pnevions
node Pojnt to both
boubly Linued Lis! Eacl
nodes
LTne last hode PontA baol to
Cìruan Linned
the tint hode
list
Advavtade ot Linu

mémont allocatiou (ho Hued

2 EasY iu sertion / dele thon of ele met.se

- File Handlju93
handlin 9 in collow& uta to oe storcd Peniout
File hoandin9
on the dis.

TYPes of

2. Binant les (-bi


1. Test les(: tt)
Not hman- he adable
Huma- head ablee
Shone data
Stones data as
teut
bor wmet ( tsten amd canig

what i8 arat t steucture ?


The mot Gownon We of stuc ture i8
arpat of steuoture.
En:

Pnognami For nccePhng 8 Printhing detuils of

Char shme 30;

mark ;
326
Main( )

Stouct student SL10 ?-[siaaas f


int i
for li=o: iz lo it)

Printt (" Enter dehls od std 7. d it+1);

br tatr de(i=oiZ10; it+)

=y. d s[iJ Sn o) CNit oo


Printt(" nube Shame)
Ntst
n a m e 7 S , J

priut (
-toa Print

nwmber |
namez

malas 25-75

Ann at Stoucture
Fextane
stoneB mwiple valne stone3 mui Ple valueB
Datn of dierent datu tYPe. o
type of the Same PeDota tYPe
Dehnition colecion, ot elementCollecton ot element&
ot the Sume datutyPe of daffenent data t4Pe.
3sHeteno ene o h 8 w
Data tomo en e o s 9 w
Ype
Ma or may not be
Memornt contiuos memort
conti 8uoW
Albcatonlocotioni 6sit in
PurPose GnouP Simi lodata Grou? related
(e-g., ist of mnus) lenent dot
age)
Student
Struct Pott
int numbons[1-j1.2,34.5}; 'Char hame [so]:
iyt rol;
oat marusj
int Scones[3) =$00, 95, 73

Arra
Anat can be of ant tyPe String Can be
contun oul
line int, loat. char ch aracterB-N
stone wuliple item8. Storeg, tent or Sequen ce
of Characters.
Arrat size once
declaned
cannot be Changed. Aryp a si2e Can be
wodihed wsin9 Pointer,
Anrat does not end. witth a Stoing i
hul chanacie. ended With a'o
chenactr.
8,. what i3 loootin 9 ?
bte
Boo tin, aso Known
Proce3 of Sturtiug a comPuter. Booti n can be
done eithen through hond wae (Pressing the Stunt
b utton) or byOivin9 sotwane comm
aud, Thene fope,
a boot device is o device thot locds the oPenatnt
SY&tem. MOneover, it Contain the instucions and
Ales Which Stunt the
Computen.
Strnetunetoe Vnion
-The neY word struot i3
Wed heeyword nion
to dehne a 8tnucture. to dehvme awnion. i8 Wsed
Shhuetwre OccuPies hither
memor 8Pace.5olib Lo Union ccupiei Lower memort
SPace. over structe
We caM acces
al memben
of Shonctune ot a tme.
We
aCCess onlt one
Cay
Al member mat
membey of uni on t o tine.
ini halized.
mat be ini haized.
Consume ware SP ace conservation of memort
than únioW vorohb
include <stdio- h inelude <3tdio-h>
shrwct Data union Data
int i ; o N A
int is
Jloat

int main
)(a i o b noA uniom Data 3N
d Hod
Struct Data d di= o; .Kotali9.nob
Printt("Aer setiu9 int: dn
= 314;
Print(" stwtne:n): 6taols Printf ( After sethng fot :
Printi Int : hd\n d-i):k 2fn' d.f)
Prin"Float:%4.2f \" -f); Priati" Int (may be Jabnte):
neturn 0 dn d.i);
retirn o,at2
3
8 What is 9otoState ment in c ? what
o it
L- NotoömP
’ The 9oto Stute ment in e is to
Program Wsin3 abel It iz
omother.Part of the
Jum?8tute ment.
aso

SYnten:el Nixvo +in clud e < tio hs


Label:M2bafo
II some Pant f the code N
nt muwM = 5
9oto label; 9NO iF ( h m s ) o
Wse
Soto Gump to
T owt of deept i4 96NlSNi Tabel
nested LooP oy condiion
wse to brenk mwiples Print" This line iB SMiPPed.\n);
LooP.
-SwiP:
'It ca lbe we d to nePeat
Some Pant of the code e Print!ais line is eneaited
tor a pari cwar condition. wsing Joto. \n")
netunn o
what i3 Pre Proce320r ?
In c lan 9ua 9e., H.e. Pre Proce 38 0n i8 a tool
that Pnocesze3 the soar Ce code betone .it iz
ComPiled. It handles dinectveg thut be ain with +,
+include,dehne, and 4fdef.These
ine
hele in Ale in cluion, macno definition, and Gondn directivez
ComPiatHon.

what i L'inean Seanch in e?


LinearSeanoh i a Simple Sear ch al3onithy
that checnsi eath elenent ot mpat seAuen ialt
wnih t Hd the' t aet vale or eaches the end.
r How it Wor:
hnst element
Stut bro the
2 each element with the ue
ComPone
3. I match dnetun ivden
Continue w n t ithe
: end.
4. Tt not ’
5. T not uwd ’ return -1.
Tine
comlewitNANO ONf
- Avera 9e Gase:o
I8t Caseio)
"Bast Cse: o1)
S. what i8the se ot conHnue in loo P in c p e
’ IM Prorammin, the coutnue' stute weut ia
Wse d SiP the Currento iteraion of a looP &
nent one
move to the
:Enample with tr ooP:
Syntafob n>iosh
continue;e at in edude < stdio.

d(i--)t
what iz the time complewtt of Bubole 8ort
BubbAe Sort i8 a simPle 3onhng aleoithm
nereate dl SwaP adia cent elementa it the
Hnat in the Wo9 Order.
ae

Case
Time complenitt EnPlanaho
ReBt Cse o() When the anpat i alnendt Sorted
(with an OPimized verzion wsing a
Fla)
Average
o) Ghener cose whene element ane
Case rendomit oder ed.
WOYt
When the aYrat8 Soypted in
Case oln)o pat neven se orden.
* SPace comPenit:

o(1) (in- place Sorting, no entra emort ea)


BUBBLE SoRT SEELCTION SoRT
Les3. elhcient Mone etti cient
Slower Fasten
Vses item enchan3in9 V3es item selectioM.

The time comPlewitt is 0()Tne ine com Plenilt in 'both


and o(n) mesPectivelt.best and worst cases B o)
Sortiu9 AL96rithm Advantase Dis advan tuge
sele cion Sort Peronma well on aa Poor eicienct when
Swal ist and no dedin with a huge ligt
231 osAitón a temport sf items

PoPwla and Eat to Doez not deal Well with a


Buble Sopt imple ment Wst contiin& a huge
number o item.

Tn3ert ion Set Simple, Perhorms well Does not deal well
On a sSmal st and Witth 4he huoe st
wini mah sPuce is reAired
Merse Sot It cn be aPPled to Requirez entra SPaeN
kles of
est Sonting aldorith m Digahantae with the
Suicu Sort and dealS verwell wonst case elfiienct.
with Lon ge st
Do- while
while
0 Do - whie JooP i3eit
0 while loop i8 entrt Coutrol AooP
Control boP.
.O A while ooP i a ADo - while looP i a
Pne- tegted LooP.taest Pozt - test ed oo P.
teststhe
(in tt test the Conditi0n ) It
at the end A the loop
betone enecuin the oop
lbodt
Semi coloy
(Tnene atne i8 no Semicolon yTne
ot the end o the JooP. at the end of the dooP.
e.9-’
e3> while ln<io)
DO2

Printd', ):
3
wide (h=l00);
MOAroa Souetn e
LefoAnratiBcolecHoo t r u c t u n e i8 the collecton
homo 9eneows ta bvs tes o Hetero Jeneows data
2 Avra data ane a cce8 3. Shoucture element ane
aLcess Wsin ) ot
Wbin indenonllano En.-S.nawe:
Eni- a[5] Cilssb
DYyamic
3. Arrat alo cales Stuh7c 3. AAtit alocate&
memort
memor.

4- Avray i de rived ata tYPe. 4. Stnucture i8 wsen defue datu

elements take
5. Aprt element acceB8 taueg 5. Stuetune
then snue ture. \Wore Hwe en arat.
Les ime
G. Sntun’ G syntun
Stuchune

datu tYPe ray name [si2e


1hes tPe variable 2

fvaniayle'i, vavjaule 2
Aray
Struere.
T En: Stouct student
it a5]: A
int Rol no.

a(0) a) a) aK a(4)
Enplain with enample.

An apray of Pointers in e i3 an aYnat Where each

element i8 a Pointey -tYPi callt Wsed to store


VarjAbles gtoiug8.

Besic concept

"A non mal nolds vodues e.o, inte er3, fhoat 3)

An
anay of Point er8 hold 3 wemorg addnesses.

USes of Apoy ot Poivten


Store shoiu33, \ezPecialt Vaeiable -len9th stin92).
"To handle 2 orpaY mape fleibl.
"To Save memortezPecialt when strin string3 oY
lar 9e structre3).

ivt mainl )
av iwt o=10) b 20 , e=303eiot..ow
pointers
rt
nt *anr31 l amay of 3 int
ar [o] = %a;

for iwt i=o; i<3


; it)3
at amr I d]= dm?i, aiJ);
Printt ("volue

out Put.
Value t arr[o] =10
value. at ar[ = 2 0
Value at arr[2-30
what i maCr0 in e g
SYmbo tuot i8
A macYo 8 a
aud rerlace d by the macro boy,
bY the PrePyoces8or
Macro
in C

TYPe o Macro3 Drehehned Macvo3

mction
ine MacrOS Live Macros

and
what ane the advantuges
Wachine level Lanouae.
blot&hbg

Advantu9e: Bretie kYoigosh to


I Fust Ene cutiou: - pireott enecuted Gy Hhe cpu Wth
elhcjet
no translajon, nauing it entemelt fast and
r compile IntenPreten - since it3 areay
NO need
in binart, the Ane%nt need to convert au thing

3 Monimwm Canbro- Givez ul covtro over hardwae


aud CPU insbucion.
OPeraion
4 Memory elhcienc i- yses le33 wmemortSince terd'k
ho aLstracho overhend.jeh
Di3 advoantages
i. Hurd to under Btand'- code i3 in bina , maving t
end and wite
to
di cult or huwang
to maue wistakes and
Eroy - Pnonei- Ver eBY
2.
them.
to debu9 or hn
hond
3. Time- con Su wimWriting even simPle Pro nawg tove

lot o hme and


evert
4. NO A3tractioni You wst manmalt wmanage
detuils ine wemont, nezter etc.
5. NOn- Port alble: Machie code is sPecihe to w
Panicwan arcitechre \ not Portable
dilerent machine 3)
Malloe () Calloc)
o c ( ) funchon
Mall
will create 1 calloc() hnGion Can as39n
Asin 3Ae blocK of
memort multi Ple bhocn wmemort for a
Size SPecited b the wer.
ar9umenta j81
2. NuWmben o argument& i8 2
2. NUmber of
calloc.
maloc 3. Malloc i3 tuster thah
Cah oc 8 8lower than to Wse cow Parred
It 8 secure
a comPane<4.
Secune
Tt 1B not to
malloc.
to call oC. lower
eti cienct i
eticiency is hilher 5. Time oc)
5. Time than mal
than cloc()
Perorm 6. It Pertorm memort
G. I doez hot inihaiZation.
imitiaize o memor.

Bran ehing
eveecution
con s e q u e n t
Rhow
ehanin9 Ahe to tue aiferet
Branehin neler to Pro ram
the
condiion,, 1t alow
loased on
ene cuhon
Path.
9oto stude went
Uncondiona Branchin %
necomun e n
wt

and wtoh
i4-ese,
Win i},
Bnanchina-
Condhona

Heraion ? multiPle timeg.


what rePeatin9
tas
menn evecut e
’ Ilerothon we need tu
when loo PB. iNig
min9, se
In Prognam i m e s , We
muwhPle
code Sramming:
Iteraion in Pro
Eamrles o
Pninhn9 nwmoeY> frdm to o
ealculat Pactonial of oa hnmber.
in a i s t , i o s t
Pnoces3 ing each ilem
For leoP
lo)
Ex:-(Printin3 humbers rom L to
to Nsol
include <stio. h
int 'main)oes

Printt i):tto
.a',
3

whide looP
Ew:-(Printin9 numlbeY Brom i to 10)
Ko include <stdio.hs
mainl)} Cievsn/
sot int
int i= L;
Whde (ie- lo)

itt

yetur o

3
Do- while Loo Cutosa
ron to o)os
(Printin 9. nwwber
t include < stdio. h>
ivnt main 07 :CniNNenDo
int i 1;

itt)
whileic= 1o);
return o;
collecton dements the.
Anpay - An
in ConH9uows mem ory ocatHon
dat type.toned
Some

t mclude. < stdio. h>


int
main()
20,30, 40, 50:
[5] -lo,
int nwwbers nnat:\n"): Aiolsot
Printf Elemevt ot the

inden d =%\ni,
Printf ( Element at
outPut

etrn 0 Element o the

= 10
3 Element. at oinden

40
4 = SO

2-D Aaryay
Out Put 9

iwt main e ) i 2 3 4 5e73

ivt numbevs [3) [9-3


1, 2. 3.4

it)
for (int i- o; i43: öt)}
foy (int J=o: je4:
Print} "d, nwmena titi1);
3
chanacter Ayay

Char

Chan name 9 ] =
ur 8apuy

be.clarin9 strin 93:

Char

char sty2[6] - 'eE0\o7:


EwamPle code
inclde <stdio. h>bnvslt

int main 0
Char name 20];
name:
Print} Enter You
8eanl.3' hame);
(name));
Print!"Len 3th : lu ", trlen
sen ch NiNohat
NNtues of Linear
ad imple went.
ver simple to nderstaud Sorted
NO need br tue datu to loe
for Sm all dataset.
workwell
8 adv a n t u e
ihtolesst
datnset
Tellccievt fon arge
. In nea
Taues on) ime. even if the element i
ed

complenity o Binart seanch


Time
midále eleweut is tar Set)
the
.Best CAse: fo o )
case ) o(lo9 n)
Aven a9e
WOrst Csei ( lo3 n)

Binar/

|lo, 207
Tanget: 407(1 :(
1. LoW = 0. high = G

2. mid (o+6/4=3N)-(u)4

4- Tan 9et found mat jnden 3.


Al80pithm3
Basic Sorno
inincneasin on deChealing
arrangin 9 element
Sortng =
der.

. What i
RecurBioni8 a Programmingtechniaue whene a

Hselt to solve. Smaller in Stan ces ef the Same Pblen,


call&
Base cese. The Condiion under hecnicn
the
which stoP
Re curSive Cse: Tne Part whene the tuncion calls itaelt
to lbney the Pno lbden down.
I. Factor\ah bin9 RecurBi0n ASNi

The etonio a wumben n (witten as n).


less than
Pro du et of alPo~ihve. inte der3
inte ers
MulkPlt all Poihve AAMAbela n down to
x3x2xg
Foy mla: n! =nx-)x(u)x...
l20
5!=Sx43x2X1

Foymua:

2. Fibonacci Series wsing Recu2\on.


Anat ew Floonacci wwwoen: o, l,1, 2,3, S,8, (3,2|3
Ewample: R)-)+lo)- 1+o-1
fl9): fr)+f)= 2|= 3
f(s) f(4)+3) -3+2-5
Fomule
F(W= F ( - ) + F ( n - l
Base Cases: Fl6)-0, F)

what i3 a stuctwre 9
A
deived data tYPe tu
alows Snoupin9 vialblez o itereut tYez wader ene
IwPotumee

’HelPs in dorta in a me anjn9tl wa.


12N
Bettey than avirat when datn 4 Pes ufeet
are

You might also like