http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic arrays



multi-dimensional array works in the same way for C++, in C you simply
allocate enough memory to hold the amount of elements that are required for
your multidimensional array using malloc.

// dim1 and dim2 are dimensions of the array
// c++
ptrArray = new char[dim1][dim2];

// c
ptrArray = (char*) malloc(sizeof(char)*dim1*dim2);

if you look up these keywords in a c or c++ reference books or on the web,
they should point you to examples of how to create dynamic arrays.

Hope this helps,


Ken
----- Original Message -----
From: <dakline@vassar.edu>
To: <gameprogrammer@gameprogrammer.com>
Sent: Friday, September 22, 2000 10:04 PM
Subject: Re: Dynamic arrays


> >char *ptrArray = NULL;
> >
> >// for c++, use new to dynamically allocate at run-time a char array of
10
> >elements
> >ptrArray = new char[10];
> >
> >// for C, use malloc() to allocate at runtime a char array of 10 elements
> >ptrArray = (char*) malloc(sizeof(char)*10);
> >
> >also remember to clean up the dynamically allocated memory using delete
> >(c++), or free (c).
>
> How would you do multi-dimensional arrays for C and C++?
>
> Thanks guys,
> SirFern
>
>
> =================================================================
> The GameProgrammer.Com mailing list is for the open discussion
> of any topic related to the art, science, and business of
> programming games. This list is especially tolerant of beginners.
> We were all beginners once
>
> To SUBSCRIBE or UNSUBSCRIBE please visit:
> http://gameprogrammer.com/mailinglist.html
>

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html