c will point to the first character, 'H' and then 'C'. It is a C-string because it points to an array of characters. You can dereference c with the subscript operator just like an array (because they are basically pointers too).
1 2 3
char* c = "Hello world";
for(int I=0; I < 11; ++I)//Note the number 11; you cannot find the length of "Hello world" from the pointer
cout << c[I];
There is no memory leak. "Hello world" is stored in the stack and not the heap.
"Hello World" is not an address in memory. How does this work.
"Hello World" is not an address, but c is. By the way, it should be declared:
constchar * c = "Hello World";
This is because the string data (the characters) is stored in your program's read-only data segment (which is the only safe assumption you can make unless you know something specific about your compiler and OS).
You can always make the pointer point to (an)other character(s):
1 2
constchar * c = "Hello World";
c = "CPlusPlus"; // c now addresses a completely different piece of read-only memory
@Daleth
Don't hardcode the length of the string. Use the fact that all c-strings terminate with a null character.
Oh, right, thanks Duoas and Gilbit. I work with C-strings and \0 so rarely that the information is kind of rusting in my head.
Dunno what else can be improved about the article (since I am still a beginner) because it is already succinct and easy to understand.