A few days ago i read about dynamic memory, and I didn't understand much could someone give me a hand?
I didn't understand what are they, what they good for.

char sbuffer[20]; //static allocation
char *dbuffer = new char[20]; //dynamic allocation
delete dbuffer; //dont forget to free it; else it leaks memoryint size = 20;
cin >> size;
char sbuffer[size]; //error, size is not known at compile time
char *dbuffer = new char[size]; //allocated as runtime, where size is known
define MAX_SIZE 20
// or
int max_size = 20;
/////////////////
char chArray[MAX_SIZE/* OR */ max_size];


Users browsing this forum: No registered users and 0 guests