Ok, so, then I have two questions.
when I do:
a = new char;
a = "a";
a = "b";
do, I need to place a
in between the assignment of a to "a" and a to "b", in order to free up the memory used by the string literal "a", that was previously pointed to by char *a? Else: memory leak?
In other words: do I need to place a delete before EVERY new assignment of char *a? Or do I only need to use delete to free up memory allocated by new.
then, I also take it, that, actually, using
char *a = "some_string";
is also valid, since I am allocating memory for one pointer (to anything, probably, but, in this case, a char), and this pointer can point to any char in memory, whether it is followed by more chars, or immediately has a null terminator in the next mem block?
Or, is it really only valid to assign a pointer to ONE SINGLE string literal to a pointer to a single char.
just as valid as
or, is only the later valid?
Thanks for your help!! :)