I'm struggling to get my head around C style strings, pointers, chars etc.
In the following bit of code i believe i've created a C-stlye string. So, constchar *strName; is a pointer to a bit of memory that contains a string? In the next line, i declare strName = "Hello World";. But is "strName" a pointer? Or a char? I'm really confused. The code works, but i don't quite understand what it is i've created!
I thought a pointer has to point towards a memory address that contains an int, double, char or whatever. But in this code it seems to me the only object created is the pointer?!
Or is the creation of constchar strName implicit when i declare: constchar *strName?
So, const char *strName; is a pointer to a bit of memory that contains a string?
Not quite. It's a pointer, but it's uninitialized and doesn't point to anything, except perhaps invalid memory.
But is "strName" a pointer?
Yes. "Hello Word" is C-string that's stored in memory somewhere. Line 7 assigns the address of where "Hello Word" is stored and places that address in your pointer.
But in this code it seems to me the only object created is the pointer?
There are two object involved here. Your uninitialized pointer and the C-string created by the compiler.
Or is the creation of const char strName implicit
No it's not implicit because you did not assign anything to it (until you get to line 7).
There are two object involved here. Your uninitialized pointer and the C-string created by the compiler.
So the "Hello World" string is only accessible via the strName pointer? If i (somehow) delete the pointer, i've lost the string forever, right?
Is it generally better to use std::string to create strings? C-style strings a bit old fashioned and convoluted, maybe? Or do they have their uses?
The following code form Learncpp.com uses the C style string (line 12), but it seems to me it would be simpler to replace it with std::string:
Yes using std::string is simpler and there is less risk of making mistakes that lead to bugs. I think you should always prefer std::string instead of C style strings unless you have a very good reason.