diff --git a/Allocating Memory/src/Allocating Memory.cpp b/Allocating Memory/src/Allocating Memory.cpp index 5385b8e..4446733 100644 --- a/Allocating Memory/src/Allocating Memory.cpp +++ b/Allocating Memory/src/Allocating Memory.cpp @@ -9,8 +9,9 @@ #include using namespace std; - +//This is a class struture in c++ class Animal { +//this is a encapsulation, it define the access level variable private: string name; @@ -39,21 +40,32 @@ class Animal { int main() { - + + //this is a allocation of memory Animal *pAnimal = new Animal[10]; - + //when you use "new", you offer memory to system from your object + //as are 10 itens, this become a array of "Animal" with 10 elements + pAnimal[5].setName("George"); pAnimal[5].speak(); delete [] pAnimal; + //this is a array of 1000 elements char *pMem = new char[1000]; + + //this clear the array, releasing memory delete [] pMem; char c = 'a'; c++; string name(5, c); cout << name << endl; + + // A pointer can become a array if you allocat memory for that + int * pointer; + pointer = new int[3]; + delete [] pointer; return 0;