malloc

Dynamic 2d array allocation and deallocation in C

0:00
↔️ ↕️

Timecodes:

dynamic 2d array allocation and

deallocation

in the following example we will

allocate a 2d array which consists of

three rows and eight columns

okay so this is our function for

allocating a 2d array don't worry about

any of the details of this at the moment

because we're going to run through it

with diagrams in great detail

let's just look at how it's used for now

so if you've got this function ready

and you want a 2d array all you need to

do is pass it the two dimensions of that

2d array

by convention i'm going to say this is

the number of rows and this is the

number of columns

and then you assign the returned value

to an int

star star a pointer to a pointer again


Related queries:


how to malloc a 2d char array in c