How to Declare Pointer to an Array of Strings in C++? Last Updated : 05 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, an array of a string is used to store multiple strings in contiguous memory locations and is commonly used when working with collections of text data. In this article, we will learn how to declare a pointer to an array of strings in C++. Pointer to Array of String in C++If we are working with C-style strings, we can directly declare the pointer to array of strings as double pointer to and for std::string object we need to declare a pointer of std::string type. Syntax to Declare Pointer to an Array of String in C++char **ptrFor std::string object use the below syntax: string* pointerToArray;C++ Program to Declare a Pointer to an Array of StringsThe following program illustrates how to declare a pointer to an array of strings in C++ C++ // C++ Program to illustrate how to declare pointer to // strings #include <iostream> using namespace std; int main() { // for C-style string const char* arr1[] = { "String1", "String2", "String3", "String4" }; // or // for C++ style stings string arr2[4] = { "Str1", "Str2", "Str3", "Str4" }; // Declare a pointer to an array of strings arr2 string* ptr_to_arr = arr2; // Accessing and printing elements of the array using // the pointer cout << "Array Elements: " << endl; for (int i = 0; i < 4; ++i) { cout << *(ptr_to_arr + i) << " "; } return 0; } OutputArray Elements: Str1 Str2 Str3 Str4 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Declare Pointer to an Array of Strings in C++? H heysaiyad Follow Improve Article Tags : C++ Programs C++ cpp-array cpp-pointer cpp-strings CPP Examples +2 More Practice Tags : CPPcpp-strings Similar Reads How to Sort an Array of Strings Using Pointers in C++? In C++, sorting an array of strings using pointers is quite different from normal sorting because here the manipulation of pointers is done directly, and then according to which string is pointed by the pointer the sorting is done. The task is to sort a given array of strings using pointers. Example 2 min read Array of Pointers to Strings in C++ In C++, an array is a homogeneous collection of data that is stored in a contiguous memory location. We can store almost all types of data as array elements. In this article, we will learn how to store the array of pointers to strings in C++. Array of Pointers to Strings in C++A pointer to a string 6 min read How to Resize an Array of Strings in C++? In C++, the array of strings is useful for storing many strings in the same container. Sometimes, we need to change the size of this array. In this article, we will look at how to resize the array of strings in C++. Resize String Array in C++There is no way to directly resize the previously allocate 2 min read How to Create an Array of Structs in C++? In C++, a struct is a user-defined data type that allows us to combine data of different types and an array of structs is an array in which each element is of the struct type. In this article, we will learn how to create an array of structs in C++. Creating an Array of Structs in C++To create an arr 2 min read How to Split a String into an Array in C++? In C++, splitting a string into an array of substrings means we have to parse the given string based on a delimiter and store each substring in an array. In this article, we will learn how to split a string into an array of substrings in C++. Example: Input: str= âHello, I am Geek from geeksforgeeks 2 min read How to Calculate the Size of a Static Array in C++? In C++, static arrays are the type of arrays whose size is fixed, and memory for them is allocated during the compile time. In this article, we will learn how to calculate the size of a static array in C++. Example: Input:myArray = {1, 2, 3, 4, 5}Output:The size of the array is 5.Size of a Static Ar 2 min read How to Declare an Array in C++? In C++, an array is a collection of similar data types in which elements are stored in contiguous memory locations. In this article, we will learn how to declare an array in C++. Declaring an Array in C++In C++, we can declare an array by specifying the type of its elements, followed by the name of 2 min read How to Create a Stack of Strings in C++? In C++, Stacks are a type of container adaptor with a LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. In this article, we will learn how to create a stack of strings in C++. Creating a Stack of Strings in C++To crea 1 min read How to Print an Array in C++? In C++, an array is a fixed-size linear data structure that stores a collection of elements of the same type in contiguous memory locations. In this article, we will learn how to print an array in C++. For Example, Input: array = {10, 20, 30, 40, 50}Output: Array Elements: 10 20 30 40 50Printing Arr 2 min read How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read Like