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
, without qualifiers, defines just a single character, not a string!
You can convert a pointer to a single
to a reference, like this:
char* my_string_pointer = new char; my_string_pointer = 'a';
my_string_pointer = 'b';
my_string_pointer = '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
, although many compilers will accept if you omit the
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.
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.