The term 'reference' in C/C++ refers to a specific type qualifier that cannot be used sensically in the way you seem to intend. Moreover, the type
char
, without qualifiers, defines just a single character, not a string!
You can convert a pointer to a
single char
to a reference, like this:
char* my_string_pointer = new char[10]; my_string_pointer[0] = 'a';
my_string_pointer[1] = 'b';
my_string_pointer[2] = 'c';
char* my_char_pointer = my_string_pointer + 1; const char& my_char_reference = *my_char_pointer; char my_char = *my_char_pointer; my_char = 'd'; my_char_reference = 'e';
Note that a reference in C/C++ is always
const
, although many compilers will accept if you omit the
const
qualifier. However, the only legal point to initialize that reference is within it's declaration. You can never change this reference later in the program. Effectively, a C/C++ reference serves as an alias for the original variable that it refers to.
As a result, there are very few real uses for references in C/C++. In fact, they are usually only used for passing parameters to functions or, rarely, returning results from functions.
Tl;dr:
Your question implies a solution that doesn't make sense. I hope my explanations made that clear to you. Please specify the intent behind your question so we can provide a better solution.