Answer to question #38977 Programming, C++
To create dynamic array you should use malloc() function.
Function returns pointer at memory and accept size of array.
For example:
int *a = (int *)malloc(sizeof(int) * 10);Allocate array a[10].
More information is available here:
http://www.cplusplus.com/reference/cstdlib/malloc/
To access to some variables use "[]". Like usual array.
For example:
int *a = (int *)malloc(sizeof(int) * 10);
int i;
for (i = 0; i < 10; i++) {
a[i] = i;
}
Comments