C
Christian Kandeler
C strings have trailing zeros, but those are only important if you wish
to count out the length of the string or perform other string functions
after the assignment. You do not need to have the trailing zero.
If it does not have the trailing zero, it is not a C string.
The allocation of memory occurs either in .bss or in the heap.
The address of the string sits on the stack.
This may or may not be true, depending on your platform. And it has nothing
to do with the topic.
What I do not understand is why you think I created a memory leak.
You wrote this:
string = malloc(5);
string = "hello\n";
How could it be any more obvious? You are allocating five bytes of memory
and then you immediately throw away the information about where it is
stored. There now is no way for you to free it, which means you have
created a memory leak. I suspect, though, that you believe the second line
stores the "hello\n" string in the allocated memory. In that case you
definitely need to read a book on C. Not to mention that if your assumption
was true, the whole thing would be even worse as you'd cause undefined
behavior.
Christian