Hi, I am a little confused with difference and usefulness of: char list[10] vs char *list
Is is that the first you must declare size of array (c-string is that what this is) during compile time whereas the second is dynamic array (dynamic c-string) so that we can declare during run time which is better (no wasted memory allocated)?
The first is an array of 10 characters, which may or may not represent a null-terminated character sequence.
The second is a pointer to a modifiable character, which may or may not be an element of some array of characters, which may or may not represent a null-terminated character sequence.
There isn't much to compare unless you have code samples which demonstrate the intended use. If your goal is to work with strings, use std::string.
char list[10]; is an array of 10 chars (size is 10 bytes).
char *list; is a pointer to a char (size is typically 4 bytes).
The C programming lanuage didn't really have a string type. But it was decided to implement string as a sequence of characters followed by character zero, which we call null. The language syntax was tweaked to support the initialisation of strings, and a set of string functions added as a library.
char list[10]; = "me"; is an array of 10 chars. list[0]='m', list[1]='e', the rest have zero. You read/write the content of this array as much as you like.
char *list = "me"; "me" is a three character array set up somewhere in memory ('m', 'e', zero) and list points to the first element. You should never try to overwrite the content of such a string as you don't know where the string actually lives.
I don't know of such examples, at least not what would be needed to someone new to the language -- I use char* sometimes to access binary representations of trivially-copyable objects, but I doubt that's what you're looking for. If your goal is to work with strings, use std::string.
if a sequence of valid single or multibyte characters is null-terminated, certain library functions process it as a string as well, that's what is broadly called "c-strings".
@kbw: char *list = "me"; is invalid C++ (was deprecated C++ until last year)
I have only ever used character arrays when I need an array of values that don't exceed the range -128 to 127 or 0 to 255. Sometimes, though, I use them to interact with low-level functions that want me to give them a pointer to the first character in a string that ends with a null character.