[Dev-C++] dynamic allocation and structs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Scott W. <se...@al...> - 2002-10-24 12:18:03
|
Hi,
I'm working in C (no C++ please). Got a couple of questions related to
dynamic allocation and in particular, dynamically allocating an array of
structs.
First, what is the duration of memory allocated by malloc (etc.)? In
particular, I want to dynamically allocate/de-allocate several global
variables within a single subroutine called from main and so want to be sure
that the allocated memory exists beyond the scope of that subroutine.
Second, it is my understanding that it is perfectly acceptable to have an
array of structs. E.g.,
struct mystruct {
double var1;
long var2;
etc...
}
. . .
struct mystruct data[100];
Is this correct? If so, what then is the calling sequence to dynamically
allocate an array of structs, and, in particularly, make the result
available globally?
Thanks for your help (& sorry if this is naive).
Scott Williams
|