Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ dynamic array

//A dynamic array is a pointer that contains multiple objects or pointers.

int size = 5; //Size of the array

/*
"new" keyword tells your computer to allocate memory
and return a pointer to that memory.
*/

int* array = new int[size];

int* array = new int[size] { 5, 6, 1, 2, 8 }; //Optional initializer

/*
Always use delete or delete[] to free a dynamic pointer.
Do not use to free a pointer or an array that was not created with 
"new" or "malloc()"
NOTE: delete frees a pointer whereas delete[] removes an array.
*/
delete[] array;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dynamic #array
ADD COMMENT
Topic
Name
6+5 =