It's quite complex to explain it on the fly, but i'll show you the main difference:
Static array:
|
char Variable[8] = "Test.";
|
Variable is a "char [8]", also "char *".
In fact, you can define values to create a Array like this.
1 2
|
const unsigned int Size = 8;
char Variable[Size] = "Test.";
|
This is the same.
Why did i use "const" ?
Try compiling it without "const".
It says it needs a constant value to declare an static array.
This is why we use Dynamic Arrays:
1 2
|
char * Variable = new char[8];
strcpy(Variable,"Test.");
|
Variable is a "char *", but not a "char [8]".
To define its value you cannot include it after "new char[...]" but must use strcpy, or similar.
You still can access it like Variable[0], Variable[1]...
Now...
The difference:
1 2 3
|
unsigned int RandomValue = 8 + rand() % (512-8); // Random Number Between 8 and 512
char * Variable = new char[RandomValue];
strcpy(Variable,"Test.");
|
It works!
You can use variables to create arrays of unlimited sizes, just like std::string or std::vector.
Remember to delete them anyways.
OT: For today i have to go, good luck with your game! ;)