Ok, so, then I have two questions.
a):
when I do:
1 2 3 4 5 6 7 8 9
|
char *a;
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.
and, b):
then, I also take it, that, actually, using
1 2
|
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.
I.e., basically:
is
just as valid as
or, is only the later valid?
Thanks for your help!! :)