   Deleting character arrays.
  What exactly happens when I do the following?char* sentence = "Hello World.";My initial assumption was that the compiler interpreted that to be:char* sentence = new char[13];sentence[0] = ''H'';sentence[1] = ''e'';...sentence[12] = 0;But unfortunately this hypothesis is disproved because when: delete[] sentence;my program crashes?So I''m interested in knowing when am I supposed to delete character pointers, or if I should even bother deleting them.  Does the compiler automatically delete them? 
  The statement:char * sentence = "Hello World.";generally is implemented by the compiler by placing a block of memory in a data segment, initialized by the string "Hello World." The char pointer is just a pointer to this area in the data segment. It''s not part of the heap so deleting it isn''t a well formed concept. ;  The string that you allocate is actually static memory, allocated at compile time.  The string is actually in the exe file, already allocated.  So calling delete on it is indeed correct, since it wasn''t dynamically allocated.  It will clean itself up when the program terminates.  Well, actually, there is no cleaning up to do.  The program exits, the OS frees the memory that was used by the actual exe file itself, and the string is gone, since it was part of the exe. ;  It really should beconst char * sentence = "Hello World.";Trying to change the string would be really bad, since the string is probably in a region of memory marked as readonly.Additionally, even if it did work, the compiler usually stores identical constants in the same location, so changing sentence would change every constant string in the program too.Example: #include <stdio.h>#include <string.h>int main() {  char *sentence = "Hello World.";  strcpy(sentence, "Test.");  puts("Hello World."); }This will do one of three things:- Crash, as the OS detected we changed something we shouldn''t have.- Print "Test."- Print "Hello World." ;quote:Original post by Kranar  So I''m interested in knowing when am I supposed to delete character pointers...When you allocate them.quote:Does the compiler automatically delete them?No. Failure to deallocate allocated memory is called a memory leak. 