In C++, I have a char array defined as:
char miniAlphabet[] = {'A','B','C','D','E', '\0'};
I want to modify the values of this array from other functions without passing it to those functions. This is where you use pointers right?
So my question is what is the correct way to make a pointer to this char array. Would I just make a pointer to the first element and then when I want to modify the values I step through memory until I hit the end character?
These are equivalent.
Note that the
()are useless for the operators’ precedence, soIn C/C++ the name of an array is a pointer to the first element of the array.
You can then use pointers’ math to do some magic…
This will point to the second element:
like
or