#include#include using namespace std; int main() { string names[] = {"John", "Jane", "David", "Lisa"}; int num_names = sizeof(names) / sizeof(names[0]); cout << "The last element of the array is: " << names[num_names - 1] << endl; return 0; }
#includeIn both examples, the cpp StringArray end is used to access and modify the last element of the string array. It belongs to the standard C++ library.#include using namespace std; int main() { string names[] = {"John", "Jane", "David", "Lisa"}; int num_names = sizeof(names) / sizeof(names[0]); names[num_names - 1] = "Mary"; cout << "The last element after modifying is: " << names[num_names - 1] << endl; return 0; }