const char* vs const char[]

Is there any difference between const char* and const char[]?

1
2
  const char* word = "word";
  const char word1[5] = "word";


I would like to determine the type of a string literal before it's being passed to a function. Ex:

 
  void func(const string &) { /* ... */ }
const char* word = "word";
Type of word is 'pointer to const char'
It is initialised to contain the address of the first character of the string literal "word"

const char word1[5] = "word";
Type of word1 is 'array of 5 const char'
Its members are initialised with the characters in the string literal "word"


> I would like to determine the type of a string literal before it's being passed to a function.

The type of a narrow string literal (always) is 'array of n const char'
The type of "word" is 'array of 5 const char'.
A string literal has a static storage duration.
Topic archived. No new replies allowed.