Let's say I do something like:
char* test[] = {"foo","bar","car"};
What exactly is this equivalent to if I did it the long way? Is this automatically creating memory that I will need to free? I'm just sort of confused. Thanks.
You are declaring an array of pointers. The pointers point to string literals.
The variable test
follows the normal rule, if it's an automatic variable(scope inside some function), when out of the function, it gets out of scope, so you don't have to free the memory. If it's statically allocated(global or static
variable), it has a life as long as the program, so you don't have to free the memory either.
The string literals that the pointers point have static storage, so you don't free them either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With