Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Allocating Memory/src/Allocating Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include <iostream>
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;

Expand Down Expand Up @@ -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;
Expand Down