How to Initialize Vector of Char Arrays in C++? Last Updated : 29 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a vector is a dynamic array that can grow and shrink in size. A char array is a sequence of characters, typically used to represent strings. In this article, we will learn how to initialize a vector of char arrays in C++. Example: myVector: {“apple”, “banana”, “cherry”}Initializing a Vector of Char Arrays in C++ We cannot directly store the char array into the vector, but we can store them as pointers. To initialize a vector of char arrays in C++, we can use the list initialization where each element is a string literal. The pointer to this string literal is then stored inside the vector of char arrays. Note: It is strongly recommended to avoid using array or pointer to arrays as the data type of the vector. C++ Program to Initialize a Vector of Char Arrays C++ // C++ Program to illustrate how to initialize a vector of // char arrays #include <iostream> #include <vector> using namespace std; // Driver Code int main() { // Creating a vector of char arrays vector<const char*> myVector = { "apple", "banana", "cherry" }; // Displaying the vector elements for (int i = 0; i < myVector.size(); ++i) { cout << myVector[i] << endl; } return 0; } Outputapple banana cherry Time Complexity: O(N), where N is the number of char arrays. Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article How to Initialize Vector of Char Arrays in C++? D denzirop9v Follow Improve Article Tags : C++ Programs C++ STL cpp-string cpp-array cpp-vector CPP Examples +3 More Practice Tags : CPPSTL Similar Reads How to Initialize 2D Vector in C++? Initializing a 2D vector refers to the process of assigning initial values to the elements of a 2D vector. In this article, we will learn different methods to initialize a 2D vector in C++.The simplest way to initialize a 2D vector is by passing the elements inside an initializer list. This method i 3 min read How to Initialize 3D Vector in C++ STL? Initializing 3D vector refers to the process of assigning the initial values to the elements of 3D Vector. In this article, we will learn different methods to initialize the 3D vector in C++.The simplest ways to initialize the 3D vector is by passing the elements inside the initializer list. This me 4 min read How to Create a Vector of Arrays in C++? In C++, an array is a collection of elements of a single type while vectors are dynamic arrays as they can change their size during the insertion and deletion of elements. In this article, we will learn how to create a vector of arrays in C++. Example: Input: arr1 = {1, 2, 3}; arr2 = {4, 5, 6}; arr3 2 min read How to Initialize a Deque from a Vector in C++? In C++, the Standard Template Library(STL) provides a container deque also known as a double-ended queue where insertion and deletions are possible from both ends. On the other hand, vectors are dynamic containers that can resize themselves during the insertion or deletion of elements. In this artic 2 min read How to Initialize an Array in C++? In C++, an array is a collection of similar datatypes stored in contiguous memory locations in which each element can be accessed using their indices. In this article, we will learn how to initialize an array in C++. Initializing an Array in C++To initialize an array in C++, we can use the assignmen 2 min read Like