0% found this document useful (0 votes)
46 views

Array

1. The document discusses pointers and dynamic memory allocation in C programming. 2. It provides examples of using malloc() to dynamically allocate memory for arrays and using pointers to reference array elements. 3. The examples demonstrate how to create a 2D dynamic array, sort an array using bubble sort, and search an array using a function that takes the array and size as parameters.

Uploaded by

Sk Samim Ali
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)
46 views

Array

1. The document discusses pointers and dynamic memory allocation in C programming. 2. It provides examples of using malloc() to dynamically allocate memory for arrays and using pointers to reference array elements. 3. The examples demonstrate how to create a 2D dynamic array, sort an array using bubble sort, and search an array using a function that takes the array and size as parameters.

Uploaded by

Sk Samim Ali
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/ 11

Autsayd

Ohat is Auays? Hoo oloes


aH

e cohg ous memoy Aoca ton


Ex

Ctes te
dting ype Cam stoHed too name

suay teporese nded in m


Q emoy tse

4 81G 20

too clmnsional away oymomtying


Pointer im c onguage
oimemiom q poide i
This meons hd block od dize colum data yPe
memay
alloted si g ma lloc qmd Poimt ey atemeic
# inelude < stdio"h>
+ inclode <std bhS
int maim C)

int tow2 colm: 3,


nt at (int t) malloc oo l gize o (iut))

fo (y=0 < ol} 3+t)


Rin Tie matix element ane")3
For (izo ikyouw it+)

fot (3=o, 3<col, Jtt)

Fuee (a)

3.

ust douwn Eu di1 e4en ce blw malloc () and Calloc C)

Malloc) function Heo te bingle blwck m


Size .

Calloc ) function usiyn muliple block o} me mos to a digle


Nasiable.

wwhat s obbipted ania ble

Subsei pted vaioble ae eused do stoed the Valus


Some ype Son 9m
ho mt
t also Lingle

Explain "c aloesnt BuppoHt Boumd cheeing .


(b)
duppot{ boumd
beauye it it
c oloes not cheekim cAuxing t give
anguge that ie odesiymecl Ses
o low lovel poagtom ing m y ord yste g
o HGel,

Poegia mmet disiect contnel ovew me


a complete
G- Porogio mr
me

mesn

elementJ piniple Pingor

4nclude < 3tdio ohy


main (0

Int a[o][], m,i,3, 3om

Poimt7 (^\ Ente the motsix \n"):

for (i=o ; i<m; i++)


y3+t)
fot (3-0 3<m
[3);
cong Cd4, a [t]

i<mg I+ +)
fo(iso3
om
t+ aJ[l;
the matuix od, 8um )
Point (1n tora ce o
3
Out Put matix :3
EnteH o d t o) 4he

Gnte he abi

o the
tsace
Dynamic alocoti om the memy
Anocatom a da
dymomic meme mosy ltecslfon
ime ol exeeution (oton me) i

The
uncafon Callo:) and malloc () upport alloca tion

woid Pi
Potogotame do in put a xn matis ond
kla mai mum element oh ll mateip

t output
inclvde Stdio h> Entet al! elemen" He
# include < conio h> matix
int maimc)

int mat [31[3]


i, 3, max
Pount"Enteg ang 3*3 matix ")1,
Fo (i-o iez; i+t)
kangest elemet 9,

Max =

for(izo; ic9; tt)


fo (s0; J<3 Jtt)
i9 (max< mat IrB)

Point \n Lagest Eloment -%d", Maxsi


geteh () 1
() sisHngiah betueem tatic and by no miG

Btatic Statte doay


fotom the 8tack.
A
Stati avvay Vaviable hold a vale e ty Pe uay.
dy na mic ay ausoble hold 9 Potmti to

Stati Auy Example


int Size t
inseyt ony lo eleoment.

Pymamic Aay Cxo m le

alal1p

(e) Tuoo dimensio mel pyo mic Ay.


be dyamicaly alloted in
Two almenbiomal cAy
us ing simgle Paint
(b) tonetion arotuy .i»py
aysnaida la mame) kuncton

del bubble Sest t (an)


n: lem (aoi)

fot J in stonge (o, m- - )

t Exam Ple ser


ek maim ()

aiay ls,s, 2, , ]

bubble- Baxt (av ay)


Roint Batted , asoray'

maim C)

Gut put

osuginal
8,9
, L,5, N,
Baetad atay:
wsit Q
foegmme oich iee ceat omates
Toanpase te mat by Passig to be Pun ctom,

# fnctud e stdioh>

int mm'
Ente 4he nombe l tow and colomn
Scam( /.d /-d", m,sn)
int a iol[10l:
Yoint (yn Enter 4he element of 4he matY ic-p \n)';

3
far (imt 3=0 3 m 5 Itt)

Se am7 ( . d at
3
3
footl"\n The element im he matoix aHe
foot (int i=0 i<m ; itt)

3
au [e1])

foot (int I=0, iemit+)

fonil" \n AteH ttansPoe the element ae ... \w);


foy (in+ I=03 icm 3 itt)
3

etun Ex

Out Pu
Entey 4he hDmbeY o) otou and oloan 3 3

En+eY the ele ment o the

The elemed ate ?n he motríyate.

fams pode ho clemed ane

4
uShat
oo Poimten Explim wih Crample.
uwhat
blo ny and Poiont
Cumput
imdexed et yaú able whese -tle Vaiable QHe Poimte

emoy
Ex ample
bo K 4e Pto qYamme hat demo nstte
ho u one

+ include <s4dlooh
+ de7ine Size (0

int

forl1-0, i<3;i4t)

narmal btoes Valee o Naveible domd.


’ Point aoy btore 4 te Qdoye ss o Vasble

s ally ay cam stae the nw mbet ol element im dome J'ze as the


Size o} +he aoro) Vau'ob le. A Point Vaiable cam stoe tho addsess
one Vaieble ad atíone
Roregoammt using proco duce/Qumctoy
Hhe Io0- 000t tem pid ?t ond

Tateger the alome


# include <stoio h

nclode. < tHme. >

int cyeateA Jt ay Cint


Size)
int aoay =
(Int mall oc (&ize tsiye ok (Tnt)3
Ueton

Void
Bl Aray (int

&tand ( time (wuLL))


i++)

aray i1= Mand ()99014+ 100,

Void Point Aoay (I(tn aotay s iint size)

int ("%d ", oay U);


3
fnt sCa
1sporeent(nl" aoray, int dize int mumbex)

(woay ]= numbot )
Hetu

int maim ()
'nt Si2
Poi nt Entey +he te aay

int

Aoay (aay, &ize);


Pos at " Aay etment a),
bint Avoray (Asoay Bie );
int mumbe
nombeH to checK ) Besemt ion the a y"),

Pintl"hd 'is Resert in the aoy\" nombo)


else

(woay)'

You might also like