Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

heap allocated array in c ++

//                                 Heap allocated array in c++
//using std::vector
#include <vector>
std::vector<myarray> bestArray(100); //A vector is a dynamic array, which (by default) allocates elements from the heap

//or managing memory yourself
myarray* heapArray = new myarray[100];
delete [] heapArray; // when you're done

//How to use vector to put elements inside the array.
// C++11:
std::vector<myarray> bestArray{ 1, 2, 3 };

// C++03:
std::vector<myarray> bestArray;
bestArray.push_back(myarray(1));
bestArray.push_back(myarray(2));
bestArray.push_back(myarray(3));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #heap #allocated #array
ADD COMMENT
Topic
Name
4+1 =